[08/24/2010] Design patterns, part 1.


The idea: write down and catalog common interactions between objects that programmers have frequently found useful.

23 patterns are divided into 3 types:
Creational patterns: ones that create objects for you, rather than having you instantiate objects directly. This gives your program more flexibility in deciding which objects need to be created for a given case.

Structural patterns help you compose groups of objects into larger structures, such as complex user interfaces or accounting data.

Behavioral patterns help you define the communication between objects in your system and how the flow is controlled in a complex program.

The Learning Process

1. Acceptance.
2. Recognition.
3. Internalization.

Notes on OO Approaches
– The fundamental reason for using varies design patterns is to keep classes separated and prevent them from having to know too much about one another. (encapsulation & inheritance)
– DP suggests that you always Program to an interface and not to an implementation: the top of any class hierarchy with an abstract class, which implements no methods but simply defines the methods that class will support.Then in all of your derived class you have more freedom to implement these methods as most suits your purposes.
Favor object composition over inheritance: object composition or encapsulation of several objects inside another one. Your new object can have the interface that is best for what you want to accomplish without having all the methods of the parent classes.

(from Design Patterns – Java Companion | James W. Cooper)