oop

OO Design, open/closed principle question

I've been thinking about this object oriented design question for a while now and have unable to come up with a satisfactory solution, so thought I'd throw it open to the crowds here for some opinions. I have a Game class that represents a turn based board game, we can assume it's similar to Monopoly for the purposes of this question. I...

What are the differences between struct and class in C++

This question was already asked in the context of C#/.Net. Now I'd like to learn the differences between a struct and a class in (unmanaged) C++. Please discuss the technical differences as well as reasons for choosing one or the other in OO design. I'll start with an obvious difference: If you don't specify public: or private:, memb...

What is the correct way to design/implement two (or more) classes that have "has a" relationships with the same object?

Suppose I have a design like this: Object GUI has two objects: object aManager and object bManager, which don't ever talk to each other. Both aManager and bManager have object cManager as an attribute (or rather a pointer to cManager). So when aManager modifies its cManager, it's affecting bManager's cManager as well. My question is w...

Is there anything wrong with returning default constructed values?

Suppose I have the following code: class some_class{}; some_class some_function() { return some_class(); } This seems to work pretty well and saves me the trouble of having to declare a variable just to make a return value. But I don't think I've ever seen this in any kind of tutorial or reference. Is this a compiler-specific t...

From small to large projects

I've been quite used to working on small projects which I coded with 1,000 lines or less (pong, tetris, simple 3d games, etc). However as my abilities in programming are increasing, my organization isn't. I seem to be making everything dependent on one one another, so it's very hard for me to change the implementation of something. ...

Design Principles

What principles do you generally follow when doing class design? ...

Should entities have behavior or not?

Should entities have behavior? or not? Why or why not? If not, does that violate Encapsulation? ...

Should I inject things into my entities?

When using an IoC container, is it considered good design to inject other classes into them? i.e. a persistence class ...

Modularity of Classes

Are there any tips or tricks to make my classes and application designs more modular? ...

Information Hiding and Properties

Does Information Hiding mean I should minimize the number of properties my classes have? Is that right? Do you tend to make your classes private fields with methods? ...

How does one elaborate design using CRC cards?

I've always been wondering how people use CRC (class responsiblity collaboration) cards. I've read about them in books, found vague information on the internet, but never grasped it really. I think someone ought to make a youtube video showing a session with CRC cards, since one of my books described it as being very hard to formulate in...

Black-box vs White-box Reuse

What are the pros/cons of using black-box reuse over white-box reuse? ...

Does several levels of base classes slow down a class/struct in c++?

Does having several levels of base classes slow down a class? A derives B derives C derives D derives F derives G, ... Does multiple inheritance slow down a class? ...

Message passing between objects - How to refer to the target object?

The most basic task in an object oriented environment is executing a method on an object. To do this, you have to have a reference to the object on which you are invoking the method. Is the proper way to establish this reference to pass the object as a parameter to the constructor (or initializer method) of the calling object? If object...

OO Javascript : Definitive explanation of variable scope

Can someone provide an explanation of variable scope in JS as it applies to objects, functions and closures? ...

What is a metaclass in Python?

I´ve mastered almost all the Python concepts (well, let´s say there are just OO concepts :-)) but this one is tricky. I know it has something to do with introspection but it´s still unclear to me. So what are metaclasses? What do you use them for? Concrete examples, including snippets, much appreciated! ...

How do I unit-test inheriting objects?

When you use composition, then you can mock the other objects from which your class-under-test depends, but when you use inheritance, you can't mock the base class. (Or can you?) I generally try to prefer composition over inheritance, but sometimes inheritance really seems like the best tool for the job - well, at least until it comes t...

Dynamic class variables

Does PHP have a method of having auto-generated class variables? I think I've seen something like this before but I'm not certain. public class TestClass { private $data = array(); public function TestClass() { $this->data['firstValue'] = "cheese"; } } The $this->data array is always an associative array but they ...

In OOP, In what cases do you act on an object instead of letting the object act ?

In what cases,or for what kind of algorithms, do you start using your objects as data structure with methodes outside of the objects (ie : Tree Walking, etc...). What scheme do you use ? (Visitor ? pattern-matching ?) Or do you think an object should always be the only one allowed to act on its own data ? ...

In MATLAB, can a class method act as a uicontrol callback without being public?

In MATLAB 2008a, is there a way to allow a class method to act as a uicontrol callback function without having to make the method public? Conceptually, the method should not be public because it should never be called by a user of the class. It should only be called as a result of a UI event triggering a callback. However, if I set th...