Make your own free website on


Should You take this tutorial?

For some lucky people, design patterns are obvious tools and they grasp their essential utility just by reading the summaries or intents of patterns. For the rest of us, there is a slow induction period after we’ve read about a pattern followed by the proverbial “Aha!” when we see how we can apply them in our work. If you fall under the latter of the two categories and want to learn about design patterns as a means of improving your object-oriented design and development skills then you best continue reading. This tutorial assumes that you are familiar with an object oriented language such as Java and basic oops concepts such as polymorphism, inheritance and encapsulation. Check out the SCEA resources section for links to some of the free books and other resources on design patterns.
**********PART 1: FUNDAS FROM THE GANG OF FOUR**********
Part 2  
FUNDA NO 1: Program to an Interface and not an Implementation. Implementation reuse (i.e. Class Inheritance) is basically a mechanism for extending an applications functionality by reusing functionality defined in the parent class. Inheriting from an abstract base class is also important. WHY? Because polymorphism depends on it... Basically what that means is, you should define the top of any class hierarchy with an abstract class, which simply defines the methods that class will support. Then, in all of your derived classes you have more freedom to implement these methods as most suits your purposes. The two main benifits from this approach are:- (Polymorphism) - Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface/type the clients expect. (Isolation) - Clients remain unaware of the classes that implement these objects. Clients only know about the abstract classes/interfaces. Creational Patterns ensure that your system is written in terms of interfaces and not implementations. This greatly reduces implementation dependencies between sub systems. FUNDA NO 2: Favour Object composition over class inheritance Object Composition allows us to extend functionality by encapsulating several objects inside another one. WHY favour it??? Because Inheritance breaks encapsulation and Composition doesnt.. Firstly implementation inherited from parent class cannot be changed at runtime. Generally the sub class also becomes so tigtly bound to the implementation of the parent class that any changes to the parent class will force the sub class to change. This reduces sub class reusability. Object composition is defined dynamically at runtime through objects acquiring references to other objects. Composition requires objects to respect each others interfaces. The merits of composition become apparent when your new object can have the interface that is best suited for what you want to accomplish without having all the methods of the parent classes, since objects are accessed solely through their interfaces,we dont break encapsulation. Objects having the same type are interchangeable at runtime. (Polymorphic) Favouring object composition also helps keep each class encapsulated and focussed on one task. In summation we can say that inheritance and composition work together. Designers and developers often overuse inheritance as a reuse technique and designs are often made more reusable by using object composition. Delegation - A Reuse Technique Delegation is a way of making composition as powerful for reuse as inheritance. In delegation there are two objects involved with handling a request the recieving object delegates operations to its delegate. The main advantage of delegation is that it makes it easy to compose behaviors at runtime and to change the way objects are composed. Eg. A window can become circular at runtime simply by replacing its rectangle instance with a circle instance, assuming that rectangle and circle have the same type. Disadvantage is that delegation due to its dynamic, highly parameterized nature is complicated and is prone to runtime inefficiencies. Some Design patterns that use delegation are State, Strategy and Visitor. Parameterized Types(generics) - A Reuse Technique Another technique for reuse is by using parameterized types. This technique lets you define a type without specifying all the other types it uses. The unspecified types are supplied as parameters at point of use. Eg. A List class can be parameterized by the type of elements it contains. To declare a list of Integers you pass "Integer" as a parameter to the List parameterized type. Similarly to declare a String List you pass "String" as a parameter to the List parameterized type.

What are Design Patterns

The concept: abstracting solutions to recurring design problems.
Christopher Alexander says "Each Pattern describes a problem which occours again and again in our environment and then describes the core of the solution to that problem in such a way that you can use this solution a million times over, without ever doing it the same way twice." The Gang of Four described patterns as "a solution to a problem in a context". These three things -- problem, solution, and context -- are the essence of a pattern.
Design Pattern Classification
Creational Abstract Factory
Factory Method
Structural Adapter

Creational Patterns

Creational patterns abstract the creational proces. Typically, the details of the classes that are created are encapsulated by an abstract superclass and hidden from the client class, which knows only about the abstract class or the interface it implements. The specific type of the concrete class is typically unknown to the client class... WHEW!! Why is all this necessary you ask... It helps make the system independent of how its objects are created, composed and represented. This in turn makes your system extendable and more importantly reusable.

The Abstract Factory Pattern

Part 1 || Part 2
Definition: ADVANTAGES: Use Abstract Factory pattern when

The Factory Method

Part 1 || Part 2
Definition: Advantages: Use Factory pattern when

The Builder Pattern

Part 1 || Part 2
Definition: Advantage: Use the Builder pattern when

The Prototype Pattern

Part 1 || Part 2
Definition: Advantages: When to use Prototype

The Singleton Pattern

Part 1 || Part 2
Definition Advantages Use Singleton pattern when

Structural Patterns

Part 1 || Part 2
Structural patterns prescribe the organization of classes and objects, how classes and objects can be combined to form larger structures. These patterns introduce a level of indirection between a client class and a class it wants to use. The difference between class structural patterns and object structural patterns is that class patterns describe how inheritance can be used to provide more useful program interfaces. Object patterns, on the other hand, describe how objects can be composed into larger structures using object composition or the inclusion of objects within other objects

The Adapter Pattern

Part 1 || Part 2
Definition Advantages: Use Adapter Pattern when:

The Bridge Pattern

Part 1 || Part 2
Definition Advantages Use Bridge Pattern when:

Composite Pattern

Part 1 || Part 2
Definition Advantages: Use Composite Pattern when:

Decorator Pattern

Part 1 || Part 2
Definition Advantages Use Decorator Pattern when:

Facade Pattern

Part 1 || Part 2
Definition Advantages Use Facade Pattern when:

Flyweight Pattern

Part 1 || Part 2
Definition Advantages Use Facade Pattern when:

Behavioural Patterns

>>>>> HOME|| Developers Bin || Certification || Tripod <<<<<
This website is the personal website of Carl Daver.