oop

The Interface Segregation Principle

The Interface Segregation Principle says that many client specific interfaces are better than one general purpose interface. Why is this important? ...

The Open/Closed Principle

The Open/Closed Principle states that software entities (classes, modules, etc.) should be open for extension, but closed for modification. What does this mean, and why is it an important principle of good object-oriented design? ...

C++ inheritance and member function pointers

In C++, can member function pointers be used to point to derived (or even base) class members? EDIT: Perhaps an example will help. Suppose we have a hierarchy of three classes X, Y, Z in order of inheritance. Y therefore has a base class X and a derived class Z. Now we can define a member function pointer p for class Y. This is writ...

Good challenges/tasks/exercises for learning or improving object oriented programming (OOP) skills.

What is a good challenge to improve your skills in object oriented programming? The idea behind this poll is to provide an idea of which exercises are useful for learning OOP. The challenge should be as language agnostic as possible, requiring either little or no use of specific libraries, or only the most common of libraries. Try to i...

C++ Quiz - Singletons

I'll soon be posting an article on my blog, but I'd like to verify I haven't missed anything first. Find an example I've missed, and I'll cite you on my post... The topic is failed Singleton implementations - in what cases can you accidentally get multiple instances of a singleton? So far, I've come up with Race Condition on first ca...

C++ function pointers and classes

ok say I have void Render(void(*Call)()) { D3dDevice->BeginScene(); Call(); D3dDevice->EndScene(); D3dDevice->Present(0,0,0,0); } This is fine as long as the function I want to use to render is a function or static class method Render(MainMenuRender); Render(MainMenu::Render); However I really want to be able to use...

Why should the "PIMPL" idiom be used?

Backgrounder: The PIMPL Idiom is a technique for implementation hiding in which a public class wraps a structure or class that cannot be seen outside the library the public class is part of. This hides internal implementation details and data from the user of the library. When implementing the this idiom why would you place the public...

In PHP5, should I use Exceptions or trigger_error/set_error_handler ?

What are the pros/cons of doing either way. Is there One Right Way(tm) ? ...

What are the pros and cons of object databases?

There is a lot of information out there on object-relational mappers and how to best avoid impedance mismatch, all of which seem to be moot points if one were to use an object database. My question is why isn't this used more frequently? Is it because of performance reasons or because object databases cause your data to become propriet...

How do I access class variables of a parent object in PHP?

An instance of class A instanciates a couple of other objects, say for example from class B: $foo = new B(); I would like to access A's public class variables from methods within B. Unless I'm missing something, the only way to do this is to pass the current object to the instances of B: $foo = new B($this); Is this best practice...

What is the Dependency Inversion Principle and why is it important?

What is the Dependency Inversion Principle and why is it important? ...

How to remove this parallel hierarchy

I'm trying to find the best design for the following scenario - an application to store results of dance competitions. An event contains multiple rounds, each round contains a number of performances (one per dance). Each performance is judged by many judges, who return a scoresheet. There are two types of rounds, a final round (contai...

The Reuse/Release Equivalence Principle (REP)

What is the Reuse/Release Equivalence Principle and why is it important? ...

Making a PHP object behave like an array?

I'd like to be able to write a PHP class that behaves like an array and uses normal array syntax for getting & setting. For example (where Foo is a PHP class of my making): $foo = new Foo(); $foo['fooKey'] = 'foo value'; echo $foo['fooKey']; I know that PHP has the _get and _set magic methods but those don't let you use array notat...

Decorating a parent class method

Not sure if what I want to accomplish is even possible, but I'd like to make a child class have a method of the parent class be a 'classmethod' even though the method in the parent class is not. Essentiall I'm trying to accomplish the following: class foo(Object): def meth1(self,val): self.value=val class bar(foo): met...

Do fluent interfaces violate the Law of Demeter?

The wikipedia article about Law of Demeter says: The law can be stated simply as "use only one dot". However a simple example of a fluent interface may look like this: static void Main(string[] args) { new ZRLabs.Yael.Pipeline("cat.jpg") .Rotate(90) .Watermark("Monkey") .RoundCorners(100, Color.Bisque) ...

Doing away with Globals?

I have a set of tree objects with a depth somewhere in the 20s. Each of the nodes in this tree needs access to its tree's root. A couple of solutions: Each node can store a reference to the root directly (wastes memory) I can compute the root at runtime by "going up" (wastes cycles) I can use static fields (but this amounts to global...

"Winning" OO programming job interviews with sysadmin/Perl/Linux background?

Hey StackOverflow-ers, I'm a student in software engineering in Montreal. For the last 3 years I've had a few interships (once per year). The first two (in the same company) were mostly sysadmin jobs, but I did get to do a few Perl programs (mostly log file analysing and statistics generation). My other intership was in the IT security...

Design question: does the Phone dial the PhoneNumber, or does the PhoneNumber dial itself on the Phone?

This is re-posted from something I posted on the DDD Yahoo! group. All things being equal, do you write phone.dial(phoneNumber) or phoneNumber.dialOn(phone)? Keep in mind possible future requirements (account numbers in addition to phone numbers, calculators in addition to phones). The choice tends to illustrate how the idioms of Infor...

Cheat single inheritance in Java !!

I have heard there is a way to cheat single inheritance and implement multiple inheritance in Java. Does anyone know how to implement this(with out using interface)? Just out of curiosity ;-) ...