Day -1 Design Patterns

by krishnamoorthyb

I started reading the Gang of Four (GOF) book today. The concept of design patterns is really nice. I like anything related to design and found design patterns both challenging and interesting. There is a fundamental difference between a framework and a toolkit. A toolkit is a related collection of classes for general purpose use by other developers. A framework is also a collection of cooperating classes. They differ from a toolkit in that they are designed for a specific domain. They make up a resuable design for a specfic class of software.
A design pattern is a solution to a design problem just as an algorithm is a solution to a computational problem. Design patterns are well documented and have been classified into three main categories: Creational, Structural and Behavioral patterns. I spent some time in understanding the following patterns
The Strategy Pattern:
Used to encapsulate multiple algorithms that solve the same problem. For ex. different types of sorting algorithms
The Decorator Pattern
Used to embelish a software component (object) with a specific feature. The embelishment can be added and removed at runtime and hence is not coded as part of the class or via an inheritance heirarchy. Example: A scrollbar to a textarea.
The Bridge Pattern
This is used to seperate an interface from its implementation so that each can be changed without affecting the other. In effect we will have one interface that the client uses and another interface that all implementations of the functionality in question implement. The connection between the client interface and the actual interface is called a bridge. Example: An application can be designed to work on different windowing environments. Each window environment(XWindow, Microsoft) will implement a window interface. The client will be a different abstract window interface that will translate all calls to the actual window interface
The Abstract Factory Pattern
This is used when we have different families of classes and the application will use one of the families at any given point in time. A good example is the implementation of different look and feel interfaces. Each look and feel interface will have a collection of classes for each widget that can be drawn on the screen. When the application starts one of the concrete families is instantiated and used by the application.
The Singleton Pattern
This is a very useful pattern as there are many cases where we want just one instance of a class to exist. One way to do the same in C++ is not to provide a public constructor. The constructor is made private and a static method is defined on the class that returns a new instance when the first instance is created and returns a reference to this instance for evry subsequent request for an instance of the class.

Have to read a lot more on design patterns and C++ before i can get a hang of this stuff….
Also fooled around with heirarchical queries and multitable inserts in Oracle.
Good night and good luck…..