oop

When to make a object delete itself?

Callback* p = new Callback; func(p); If I want to delete the callback object, when and how to delete that? If it gets deleted early, then the callback may be failed. ...

Dropping objects on the floor

I'm creating a cell editor, but I've done (and seen) this in other code. I'm creating an object and then dropping it on the floor like this: ButtonCellEditor buttonColumn = new ButtonCellEditor(table, 2); This class takes the table and sets a TableColumnModel and custom cell renderers to it. Then, the method ends and I don't reference t...

Why do we use .NET properties instead of plain old get/set functions?

I understand the many benefits of providing an interface to access the members of a class indirectly. My question is: isn't that already something you can accomplish in just about any OO language using (something along the lines of) public int NormalClass::getQuality() { return this->quality; } and protected void NormalClass::set...

What’s the point of inheritance in Python?

I apologize if this question is long. This was part of a blog post I did some time ago, and a reader suggested me to post it on stackoverflow. I trimmed it a bit though. Suppose you have the following situation #include <iostream> class Animal { public: virtual void speak() = 0; }; class Dog : public Animal { void speak() { s...

Using base classes and method overriding to write neater code

I've heard about how base classes and method overriding can be combined to eliminate code reuse/write neater code. Is there an example available of how this can be done (in C#)? Thanks ...

Is this php code written correctly according to OO principles?

Iv been trying to get my head around object orientation and I think iv started to get some of the concepts, but im not sure. Making a google search that answers if my train of thought is correct proved to be quite hard so I decided to ask here really quick, please tell me if the question is against any rules. Im I thinking correctly in ...

What are public, private and protected in object oriented programming?

What are public, private and protected in object oriented programming? ...

Creating an object from a dynamic database call

I'm trying to make a class that takes some unspecified data from a database query (passed to my class as an array) and turns it into a PHP object with properties that are created dynamically from the data passed to it. Like so: class myLibrary_Item extends myLibrary { private function __construct($vars) ...

Is there any good php5 OOP tutorial site?

Is there any good php5 OOP tutorial site? I Googled for a while ,and found that there are all of PHP4 OOP site everywhere. ...

Open Source C++ Object Oriented Database

Hi, Is there an open source object oriented database for C++ available? I had looked at Object oriented Relationship Mapping (ORM) libraries like those posted here: http://stackoverflow.com/questions/74141/good-orm-for-c-solutions and these were intereting as well: http://stackoverflow.com/questions/600684/object-oriented-like-struct...

Overriding same method in only some child classes, how to avoid duplication?

I am using a base class and there are 5 child classes currently for it. Some of the functions are similar for 3 of the children but not all of them. I cannot introduce a new level of hierarchy as some methods are repeated in child 1,2,3 and some in 2,3,4. How best can I avoid overriding the methods in all 3 children and repeating the co...

Getters and Setters: Code smell, Necessary Evil, or Can't Live Without Them

Possible Duplicate: Allen Holub wrote You should never use get/set functions, is he correct? Is there a good, no, a very good reason, to go through all the trouble of using getters and setters for object-oriented languages? What's wrong with just using a direct reference to a property or method? Is there some kind of "semantic...

maintain object state with different pages using PHP

hi guys, how to do this using PHP OOP to maintain object state in different pages. the problem is im always instantiate the object on every page. is there a solution that i instantiate it once and maintain its object on different pages. Thanks in advance ...

Should I instantiate new objects for all different interactions?

Im having a hard time grasping this concepts of objects and how they should interact/exist. Should I for instance have different objects (well, maybee I mean connections to the database here if there is any difference) for interactions with my database whenever they are not related? Lets say I have one object that index.php uses to ge...

Building a new hierarchy, use an abstract class or an interface?

I'm preparing to build a 2D scene graph for my game, and i would like to know whether i should use at it's root an interface or two or a couple of abstract classes. Here's my requirements: Base node item needs to be able to store a matrix also needs to be able to store a list of child nodes as well as a single parent node Transform n...

How do i indicate differences in this situation?

I am building code for a 2D scene graph and i have a single abstract class, Node that will be used to indicate that a type of item can be used in a scene graph. However, classes that implement from this are of different types such as leaf nodes and transformation nodes. How would i indicate these differences? would i use attributes, othe...

C++: Will an 'empty' destructor do the same thing as the generated destructor?

Suppose we have a (toy) C++ class such as the following: class Foo { public: Foo(); private: int t; }; Since no destructor is defined, a C++ compiler should create one automatically for class Foo. If the destructor does not need to clean up any dynamically allocated memory (that is, we could reasonably rely on...

Should Guid.Empty Result in ArgumentException or ArgumentOutOfRangeException

Imagine that you have a method with the following signature: public void DoSomething(Guid id) If Guid.Emtpy represents an illegal value, which Exception type would it be most appropriate to throw? ArgumentException or ArgumentOutOfRangeException? I'm leaning slightly towards ArgumentException, since I don't think that all Guids excep...

Why do both the abstract class and interface exist in .Net?

Why do both the abstract class and interface exist in .Net ( or in C# ) if we can achieve the interface feature by making all the members in the class as abstract. Is it because: Interface exists to have multiple inheritance It makes sense to have interface because object's CAN-DO feature should be placed in an interface rather base a...

OO Design Question -- Parent/Child(ren) -- Circular?

I'm fairly new to the OO design process, so please bear with me.... I have two entities that I need to model as classes, call them Parent and Child (it's close enough to the actual problem domain). One Parent will have one or more Children -- I have not interest, in this application, in childless Parents. Where my brain is going out to...