Search Results

Search found 61651 results on 2467 pages for 'function object'.

Page 5/2467 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Domain Models (PHP)

    - by Calum Bulmer
    I have been programming in PHP for several years and have, in the past, adopted methods of my own to handle data within my applications. I have built my own MVC, in the past, and have a reasonable understanding of OOP within php but I know my implementation needs some serious work. In the past I have used an is-a relationship between a model and a database table. I now know after doing some research that this is not really the best way forward. As far as I understand it I should create models that don't really care about the underlying database (or whatever storage mechanism is to be used) but only care about their actions and their data. From this I have established that I can create models of lets say for example a Person an this person object could have some Children (human children) that are also Person objects held in an array (with addPerson and removePerson methods, accepting a Person object). I could then create a PersonMapper that I could use to get a Person with a specific 'id', or to save a Person. This could then lookup the relationship data in a lookup table and create the associated child objects for the Person that has been requested (if there are any) and likewise save the data in the lookup table on the save command. This is now pushing the limits to my knowledge..... What if I wanted to model a building with different levels and different rooms within those levels? What if I wanted to place some items in those rooms? Would I create a class for building, level, room and item with the following structure. building can have 1 or many level objects held in an array level can have 1 or many room objects held in an array room can have 1 or many item objects held in an array and mappers for each class with higher level mappers using the child mappers to populate the arrays (either on request of the top level object or lazy load on request) This seems to tightly couple the different objects albeit in one direction (ie. a floor does not need to be in a building but a building can have levels) Is this the correct way to go about things? Within the view I am wanting to show a building with an option to select a level and then show the level with an option to select a room etc.. but I may also want to show a tree like structure of items in the building and what level and room they are in. I hope this makes sense. I am just struggling with the concept of nesting objects within each other when the general concept of oop seems to be to separate things. If someone can help it would be really useful. Many thanks

    Read the article

  • Good Literature for "Object oriented programming in C"

    - by Dipan Mehta
    This is not a debate question about whether or not C is a good candidate for Object oriented programming or not. Quite often C is the primary platform where the development is happening. I have seen, and hopefully learnt through crawling many open source and commercial projects - that while the language inherently doesn't stop you if you create "non-object" code. However, you can still think in the "Object" way and reasonably write code that captures this designs thinking. For those who has done this, OO way is still the best way to write code even when you are programming in C. While, I have learnt most of it through the hard way, are there any deep literature that can help educate the relatively young guys about how to do OO programming in C?

    Read the article

  • Object-Oriented equivalent of LISP's progn function?

    - by Archer
    I'm currently writing a LISP parser that iterates through some AutoLISP code and does its best to make it a little easier to read (changing prefix notation to infix notation, changing setq assignments to "=" assignments, etc.) for those that aren't used to LISP code/only learned object oriented programming. While writing commands that LISP uses to add to a "library" of LISP commands, I came across the LISP command "progn". The only problem is that it looks like progn is simply executing code in a specific order and sometimes (not usually) assigning the last value to a variable. Am I incorrect in assuming that for translating progn to object-oriented understanding that I can simply forgo the progn function and print the statements that it contains? If not, what would be a good equivalent for progn in an object-oriented language?

    Read the article

  • Objected oriented approach to structure inside structure

    - by RishiD
    This is for C++ but should apply to any OO language. Trying to figure out the correct object oriented apporach to do the following (this is what I do in C). struct Container { enum type; union { TypeA a; TypeB b; }; } The type field determines if it TypeA or TypeB object. I am using this to handle responses coming back from a connection, they get parsed and get put into this structure and then based on the message type the appropriate fields get filled in. e.g. struct Container parseResponse(bufferIn, bufferLength); Is there an OO approach for doing this?

    Read the article

  • What is a good design model for my new class?

    - by user66662
    I am a beginning programmer who, after trying to manage over 2000 lines of procedural php code, now has discovered the value of OOP. I have read a few books to get me up to speed on the beginning theory, but would like some advice on practical application. So,for example, let's say there are two types of content objects - an ad and a calendar event. what my application does is scan different websites (a predefined list), and, when it finds an ad or an event, it extracts the data and saves it to a database. All of my objects will share a $title and $description. However, the Ad object will have a $price and the Event object will have $startDate. Should I have two separate classes, one for each object? Should I have a 'superclass' with the $title and $description with two other Ad and Event classes with their own properties? The latter is at least the direction I am on now. My second question about this design is how to handle the logic that extracts the data for $title, $description, $price, and $date. For each website in my predefined list, there is a specific regex that returns the desired value for each property. Currently, I have an extremely large switch statement in my constructor which determines what website I am own, sets the regex variables accordingly, and continues on. Not only that, but now I have to repeat the logic to determine what site I am on in the constructor of each class. This doesn't feel right. Should I create another class Algorithms and store the logic there for each site? Should the functions of to handle that logic be in this class? or specific to the classes whos properties they set? I want to take into account in my design two things: 1) I will add different content objects in the future that share $title and $description, but will have their own properties, so, I want to be able to easily grow these as needed. 2) I will add more websites constantly (each with their own algorithms for data extraction) so I would like to plan efficienty managing and working with these now. I thought about extending the Ad or Event class with 'websiteX' class and store its functions there. But, this didn't feel right either as now I have to manage 100s of little website specific class files. Note, I didn't know if this was the correct site or stackoverflow was the better choice. If so, let me know and I'll post there.

    Read the article

  • Is the "impossible object" possible in computer graphics?

    - by CPP_Person
    This may be a silly question but I want to know the answer to it. I saw this thing called the "impossible object", while they're many different images of this online, it's suppost to be impossible geometry. Here is an example: Now as far as logic goes, I know you don't have to obey it in games, such as a flying cow, or an impossible object. So that's out of the way, but what stands in my way is whether or not there is a way to draw this onto a 3D scene. Like is there a way to represent it as a 3D object? Thanks!

    Read the article

  • Function keys on an external keyboard

    - by asymptotically
    So I bought a keyboard for my laptop. Unfortunately, it doesn't have the function key (though I know many people say it's useless). On my laptop, I control volume with the function key and F9-11. How can I get the same functionality on my external keyboard? The advanced keyboard settings don't have an option related to the function key. More specifically, it would be great if I could map it to my 'Menu' key which I'm never going to use. Or is there a way to get full functionality without it?

    Read the article

  • Javascript object list sorting by object property

    - by Constructor
    I need to do this: (sorry not in javascript syntax-still learning object language :) ) object=car attibutes:top-speed, brand.... now I want to sort the list of those cars in order by top-speed, brand... How do I do this (please note the solution must be javascript only, no php or other stuff) ?

    Read the article

  • reference function from another function

    - by JohnWong
    I forgot how to reference another function into a function in C++? In python it is declare as a class so that I can use it. double footInches(double foot) { double inches = (1.0/12.00) * foot; return inches; } double inchMeter(double inch) { double meter = 39.37 * (footInches(inches)); return meter; } I want to reference footInches in inchMeter.

    Read the article

  • Nhibernate/Hibernate, lookup tables and object design

    - by Simon G
    Hi, I've got two tables. Invoice with columns CustomerID, InvoiceDate, Value, InvoiceTypeID (CustomerID and InvoiceDate make up a composite key) and InvoiceType with InvoiceTypeID and InvoiceTypeName columns. I know I can create my objects like: public class Invoice { public virtual int CustomerID { get; set; } public virtual DateTime InvoiceDate { get; set; } public virtual decimal Value { get; set; } public virtual InvoiceType InvoiceType { get; set; } } public class InvoiceType { public virtual InvoiceTypeID { get; set; } public virtual InvoiceTypeName { get; set; } } So the generated sql would look something like: SELECT CustomerID, InvoiceDate, Value, InvoiceTypeID FROM Invoice WHERE CustomerID = x AND InvoiceDate = y SELECT InvoiceTypeID, InvoiceTypeName FROM InvoiceType WHERE InvoiceTypeID = z But rather that having two select queries executed to retrieve the data I would rather have one. I would also like to avoid using child object for simple lookup lists. So my object would look something like: public class Invoice { public virtual int CustomerID { get; set; } public virtual DateTime InvoiceDate { get; set; } public virtual decimal Value { get; set; } public virtual InvoiceTypeID { get; set; } public virtual InvoiceTypeName { get; set; } } And my sql would look something like: SELECT CustomerID, InvoiceDate, Value, InvoiceTypeID FROM Invoice INNER JOIN InvoiceType ON Invoice.InvoiceTypeID = InvoiceType.InvoiceTypeID WHERE CustomerID = x AND InvoiceDate = y My question is how do I create the mapping for this? I've tried using join but this tried to join using CustomerID and InvoiceDate, am I missing something obvious? Thanks

    Read the article

  • Getting my head around object oriented programing

    - by nLL
    I am entry level .Net developer and using it to develop web sites. I started with classic asp and last year jumped on the ship with a short C# book. As I developed I learned more and started to see that coming from classic asp I always used C# like scripting language. For example in my last project I needed to encode video on the webserver and wrote a code like public class Encoder { Public static bool Encode(string videopath) { ...snip... return true; } } While searching samples related to my project I’ve seen people doing this public class Encoder { Public static Encode(string videopath) { EncodedVideo encoded = new EncodedVideo(); ...snip... encoded.EncodedVideoPath = outputFile; encoded.Success = true; ...snip... } } public class EncodedVideo { public string EncodedVideoPath { get; set; } public bool Success { get; set; } } As I understand second example is more object oriented but I don’t see the point of using EncodedVideo object. Am I doing something wrong? Does it really necessary to use this sort of code in a web app?

    Read the article

  • Designing a class in such a way that it doesn't become a "God object"

    - by devoured elysium
    I'm designing an application that will allow me to draw some functions on a graphic. Each function will be drawn from a set of points that I will pass to this graphic class. There are different kinds of points, all inheriting from a MyPoint class. For some kind of points it will be just printing them on the screen as they are, others can be ignored, others added, so there is some kind of logic associated to them that can get complex. How to actually draw the graphic is not the main issue here. What bothers me is how to make the code logic such that this GraphicMaker class doesn't become the so called God-Object. It would be easy to make something like this: class GraphicMaker { ArrayList<Point> points = new ArrayList<Point>(); public void AddPoint(Point point) { points.add(point); } public void DoDrawing() { foreach (Point point in points) { if (point is PointA) { //some logic here else if (point is PointXYZ) { //...etc } } } } How would you do something like this? I have a feeling the correct way would be to put the drawing logic on each Point object (so each child class from Point would know how to draw itself) but two problems arise: There will be kinds of points that need to know all the other points that exist in the GraphicObject class to know how to draw themselves. I can make a lot of the methods/properties from the Graphic class public, so that all the points have a reference to the Graphic class and can make all their logic as they want, but isn't that a big price to pay for not wanting to have a God class?

    Read the article

  • complex arguments for function

    - by myPost1
    My task is to create function funCall taking four arguments : pointer for 2d array of ints that stores pairs of numbers variable int maintaining number of numbers in 2d array pointer for table of pointers to functions int variable storing info about number of pointers to functions I was thinking about something like this : typedef int(*funPtr)(int, int); funPtr arrayOfFuncPtrs[]; void funCall( *int[][]k, int a, *funPtr z, int b); { }

    Read the article

  • Must declare function prototype in C?

    - by Mohit Deshpande
    I am kind of new to C (I have prior Java, C#, and some C++ experience). In C, is it necessary to declare a function prototype or can the code compile without it? Is it good programming practice to do so? Or does it just depend on the compiler? (I am running Ubuntu 9.10 and using the GNU C Compiler, or gcc, under the Code::Blocks IDE)

    Read the article

  • Is it better to return NULL or empty values from functions/methods where the return value is not present?

    - by P B
    I am looking for a recommendation here. I am struggling with whether it is better to return NULL or an empty value from a method when the return value is not present or cannot be determined. Take the following two methods as an examples: string ReverseString(string stringToReverse) // takes a string and reverses it. Person FindPerson(int personID) // finds a Person with a matching personID. In ReverseString(), I would say return an empty string because the return type is string, so the caller is expecting that. Also, this way, the caller would not have to check to see if a NULL was returned. In FindPerson(), returning NULL seems like a better fit. Regardless of whether or not NULL or an empty Person Object (new Person()) is returned the caller is going to have to check to see if the Person Object is NULL or empty before doing anything to it (like calling UpdateName()). So why not just return NULL here and then the caller only has to check for NULL. Does anyone else struggle with this? Any help or insight is appreciated.

    Read the article

  • How to build Object Oriented Skills?

    - by cedar715
    Being a core developer for couple of years, coding applications seeing the class diagrams, sequence diagrams, I decided to improve my self, taking the next step of designing. As I'm an OO developer, I'm interested in improving my design skills. For Example, I had a hard time designing a currency converter. My questions to the SO: Is it by experience the design skills can be acquired? Will learning books/blog/material over internet etc help? Is it that one needs the domain knowledge of the application being developed? Knowing Design patterns, principles? Studying 'Code Complete' book ? Need to have Problem-solving skills? In short, given a problem, I just want to solve it in Object-oriented way??

    Read the article

  • Returning a local object from a function

    - by pocoa
    Is this the right way to return an object from a function? Car getCar(string model, int year) { Car c(model, year); return c; } void displayCar(Car &car) { cout << car.getModel() << ", " << car.getYear() << endl; } displayCar(getCar("Honda", 1999)); I'm getting an error, "taking address of temporary". Should I use this way: Car &getCar(string model, int year) { Car c(model, year); return c; }

    Read the article

  • python function that returns a function from list of functions

    - by thkang
    I want to make following function: 1)input is a number. 2)functions are indexed, return a function whose index matches given number here's what I came up with: def foo_selector(whatfoo): def foo1(): return def foo2(): return def foo3(): return ... def foo999(): return #something like return foo[whatfoo] the problem is, how can I index the functions (foo#)? I can see functions foo1 to foo999 by dir(). however, dir() returns name of such functions, not the functions themselves. In the example, those foo-functions aren't doing anything. However in my program they perform different tasks and I can't automatically generate them. I write them myself, and have to return them by their name.

    Read the article

  • Does this copy the reference or the object?

    - by Water Cooler v2
    Sorry, I am being both thick and lazy, but mostly lazy. Actually, not even that. I am trying to save time so I can do more in less time as there's a lot to be done. Does this copy the reference or the actual object data? public class Foo { private NameValueCollection _nvc = null; public Foo( NameValueCollection nvc) { _nvc = nvc; } } public class Bar { public static void Main() { NameValueCollection toPass = new NameValueCollection(); new Foo( toPass ); // I believe this only copies the reference // so if I ever wanted to compare toPass and // Foo._nvc (assuming I got hold of the private // field using reflection), I would only have to // compare the references and wouldn't have to compare // each string (deep copy compare), right? } I think I know the answer for sure: it only copies the reference. But I am not even sure why I am asking this. I guess my only concern is, if, after instantiating Foo by calling its parameterized ctor with toPass, if I needed to make sure that the NVC I passed as toPass and the NVC private field _nvc had the exact same content, I would just need to compare their references, right?

    Read the article

  • help Implementing Object Oriented ansi-C approach??

    - by No Money
    Hey there, I am an Intermediate programmer in Java and know some of the basics in C++. I recently started to scam over "C language" [please note that i emphasized on C language and want to stick with C as i found it to be a perfect tool, so no need for suggestions focusing on why should i move back to C++ or Java]. Moving on, I code an Object Oriented approach in C but kindda scramble with the pointers part. Please understand that I am just a noob trying to extend my knowledge beyond what i learned in High School. Here is my code..... #include <stdio.h> typedef struct per{ int privateint; char *privateString; struct per (*New) (); void (*deleteperOBJ) (struct t_person *); void (*setperNumber) ((struct*) t_person,int); void (*setperString) ((struct*) t_person,char *); void (*dumpperState) ((struct*) t_person); }t_person; void setperNumber(t_person *const per,int num){ if(per==NULL) return; per->privateint=num; } void setperString(t_person *const per,char *string){ if(per==NULL) return; per->privateString=string; } void dumpperState(t_person *const per){ if(per==NULL) return; printf("value of private int==%d\n", per->privateint); printf("value of private string==%s\n", per->privateString); } void deleteperOBJ(struct t_person *const per){ free((void*)t_person->per); t_person ->per = NULL; } main(){ t_person *const per = (struct*) malloc(sizeof(t_person)); per = t_person -> struct per -> New(); per -> setperNumber (t_person *per, 123); per -> setperString(t_person *per, "No money"); dumpperState(t_person *per); deleteperOBJ(t_person *per); } Just to warn you, this program has several errors and since I am a beginner I couldn't help except to post this thread as a question. I am looking forward for assistance. Thanks in advance.

    Read the article

  • Make function declarations based on function definitions

    - by Clinton Blackmore
    I've written a .cpp file with a number of functions in it, and now need to declare them in the header file. It occurred to me that I could grep the file for the class name, and get the declarations that way, and it would've worked well enough, too, had the complete function declaration before the definition -- return code, name, and parameters (but not function body) -- been on one line. It seems to me that this is something that would be generally useful, and must've been solved a number of times. I am happy to edit the output and not worried about edge cases; anything that gives me results that are right 95% of the time would be great. So, if, for example, my .cpp file had: i2cstatus_t NXTI2CDevice::writeRegisters( uint8_t start_register, // start of the register range uint8_t bytes_to_write, // number of bytes to write uint8_t* buffer = 0) // optional user-supplied buffer { ... } and a number of other similar functions, getting this back: i2cstatus_t NXTI2CDevice::writeRegisters( uint8_t start_register, // start of the register range uint8_t bytes_to_write, // number of bytes to write uint8_t* buffer = 0) for inclusion in the header file, after a little editing, would be fine. Getting this back: i2cstatus_t writeRegisters( uint8_t start_register, uint8_t bytes_to_write, uint8_t* buffer); or this: i2cstatus_t writeRegisters(uint8_t start_register, uint8_t bytes_to_write, uint8_t* buffer); would be even better.

    Read the article

  • controlling an object through another object ?

    - by Stefano Borini
    Today I've seen the following pattern: you have an object A and an object B. Object B accepts a pointer to A at its constructor. Once B is created, there's a method B.doCalc() that performs a calculation (internally using A's information). The result is obtained with method B.getResult(). In order to perform another calculation, A is modified, and B.doCalc() is called again. What is your opinion on this choice ? I would have designed it differently, but I want to hear your voice. Edit : note that my main objection is to modify A to have a different result from B, without touching B. Although similar, I think that just this discipline expresses a much better feeling of what's going on. Instead of a = new A a.whatever = 5 b = new B(a) b.doCalc() res = b.getResult() a.whatever = 6 b.doCalc() res = b.getResult() You get the a pointer object from b itself. a = new A a.whatever = 5 b = new B(a) b.doCalc() res = b.getResult() a = b.getAPointer() a.whatever = 6 b.doCalc() res = b.getResult() because it makes more explicit the fact that a is taken from b and then modified. I still don't like it, though...

    Read the article

  • Uncaught TypeError: Object [object Object] has no method 'onAdded'

    - by user3604227
    I am using ExtJS4 with Java servlets. I am following the MVC architecture for ExtJS. I am trying a simple example of displaying a border layout but it doesnt work and I get the following error in ext-all.js in the javascript console: Uncaught TypeError: Object [object Object] has no method 'onAdded' Here is my code: app.js Ext.Loader.setConfig({ enabled : true }); Ext.application({ name : 'IN', appFolder : 'app', controllers : [ 'Items' ], launch : function() { console.log('in LAUNCH-appjs'); Ext.create('Ext.container.Viewport', { items : [ { xtype : 'borderlyt' } ] }); } }); Items.js (controller) Ext.define('IN.controller.Items', { extend : 'Ext.app.Controller', views : [ 'item.Border' ], init : function() { this.control({ 'viewport > panel' : { render : this.onPanelRendered } }); }, onPanelRendered : function() { console.log('The panel was rendered'); } }); Border.js (view) Ext.define('IN.view.item.Border',{extend : 'Ext.layout.container.Border', alias : 'widget.borderlyt', title : 'Border layout' , autoShow : true, renderTo : Ext.getBody(), defaults : { split : true, layout : 'border', autoScroll : true, height : 800, width : 500 }, items : [ { region : 'north', html : "Header here..", id : 'mainHeader' }, { region : 'west', width : 140, html : "Its West..", }, { region : 'south', html : "This is my temp footer content", height : 30, margins : '0 5 5 5', bodyPadding : 2, id : 'mainFooter' }, { id : 'mainContent', collapsible : false, region : 'center', margins : '5', border : true, } ] }); The folder structure for the Webcontent is as follows: WebContent app controller Items.js model store view item Border.js ext_js resources src ext_all.js index.html app.js Can someone help me resolve this error? Thanks in advance

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >