Friday 4 May 2007

BLOG 13 -Conclusion on PAFSD Module

BLOG 13

As the PAFSD module comes to an end as the semester ends, in a nutshell I can say I have learnt a lot and am thinking to apply patterns were applicable to my software engineering project.

In general I now understand what patterns are and are not. Also I now understand clearly how wrong implementation and use of catalogue patterns can lead to bad solutions hence, anti-patterns.

The introductory sections of the module dealt with Christopher Alexander’s ideas of patterns. The main focus of this module was on design patterns by Gang of Four (GoF), the elements of patterns and how to create and catalogue a new pattern using the elements of patterns by Alexander or GoF. In one of my earlier blog, I tried to explain what a design pattern is. The last sessions of this module-lecture covered Anti-patterns. (I also tried to explain Anti-patterns in one of my blogs).

GoF categorized there patterns in three groups:
Creational
Structural
Behavioral

Twenty three (23) patterns fall within these categories. They are summarized below;

Creational Patterns

Abstract Factory
This pattern is used when you want to create an instance of several families of classes.

Builder
This pattern is used when you want to separate object construction from its representation.

Factory Method
This pattern creates an instance of several derived classes.

Prototype
This pattern allows a fully initialized instance to be copied or cloned.

Singleton
This pattern can be applied to a class of which only a single instance can exist.

Structural Patterns

Adapter
This pattern is used when you want to match interfaces of different classes


Bridge
This pattern is used when you want to separates an object’s interface from its implementation

Composite
This pattern is used when you want a tree structure of simple and composite objects

Decorator
This pattern is used when you want to add responsibilities to objects dynamically

Facade
This pattern is used when you want a single class that represents an entire subsystem

Flyweight
This pattern is used when you want a fine-grained instance used for efficient sharing

Proxy
This pattern is used when you want to an object representing another object


Behavioral Patterns

Chain of Responsibility
This pattern is used when you want to find a way of passing a request between a chain of objects

Command
This pattern is used when you want to encapsulate a command request as an object

Interpreter
This pattern is used when you want a way to include language elements in a program

Iterator
This pattern is used when you want to sequentially access the elements of a collection

Mediator
This pattern is used when you want to define simplified communication between classes

Memento
This pattern is used when you want to capture and restore an object's internal state.

Observer
This pattern is used when you want a way of notifying change to a number of classes.

State
This pattern is used when you want to alter an object's behavior when its state changes

Strategy
This pattern is used when you want to encapsulates an algorithm inside a class

Template Method
This pattern is used when you want to defer the exact steps of an algorithm to a subclass

Visitor
This pattern is used when you want to define a new operation to a class without change

Cheers to you all that sent your comments. Thanks a lot and good luck

Wednesday 18 April 2007

Anti-Patterns

BLOG 12

Anti-Patterns

Coincidentally, this topic happens to be task 4 of our coursework, so I won't elaborate more on it on my blogg.In the event the patterns are not applied correctly due to negligence on the part of the developer then the pattern becomes an anti-pattern hence defeating the pattern intended role by it creator. In this light, the pattern will be seen as anti-patterns, anti-patterns are seen as negative solutions that present more problems than they address.Anti-Patterns begin with a compelling, problematic solution.

Once an Anti-Pattern has been correctly identified, its refactored solution can be used to obtain a better convergence of the underlying forces to lead you to a better understanding of the problem and an effective method of resolving the problematic solution. [SWE98]

Anti-patterns can be viewed in three ways according to W.H Brown et al; development anti patterns which comprise technical problems and solutions that are encountered by programmers, architectural anti-patterns which identifies and resolves common problems in how systems are structured and managerial anti-patterns which addresses common problems in software processes and development organizations.In summarizing; Anti-Patterns are used to quickly move from negative situations to positive solutions.

Anti-Patterns are useful for refactoring and reengineering in the computing world.

[SWE98] Anti-Patterns Refactoring Software, Architectures, and Projects in Crisis SWEE ‘98 Hays W. McCormick Lead Engineer, (http://www.antipatterns.com/briefing/sld006.htm ) slide 6

Bridge Pattern

BLOG 11

Bridge Pattern

In real life a bridge is seen or considered as a connecting / intermediate route or phase between two elements or conditions. It provides access from one point to another whether there was none before. You can choose to remove or suspend that access as you choose to.

In design patterns, there exist structural patterns by GoF, the bridge pattern. From my understanding of a bridge pattern since Inheritance binds an implementation to the
Abstraction permanently which makes it difficult to modify, a bridge pattern can be used to decouple the abstraction from its implementation so that it can be modified at anytime and then bridge or coupled again with its implementation to be used at run time. The decoupling helps the abstraction and implementation to be used independently also. GOF in there own words say that the intention for this pattern is to “Decouple an abstraction from its implementation so that the two can vary independently” [GoF]

[GoF] GoF, elements of reusable Object Oriented software, Page 157

Facade Pattern

BLOG 10

Facade Pattern

Inorder for systems to be built efficiently and also managed, the whole system should be structured into sub-systems. Facade helps provide a simple interface to a complex subsystem.

This patterns can be used were there are many dependencies between clients and the implementation classes of an abstraction. This pattern can be used to decouple the subsystem from clients and other subsystems hence promoting subsystem independence and portability.

According to GOF, the intention of this pattern is to “Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.”[GoF]


[GoF] GoF, elements of reusable Object Oriented software, Page 157

Decorator Pattern

BLOG 9

Decorator Pattern

The decorator pattern is a pattern used when u need to add more features to an object. For example in real life, a manufacturer may create a basic car, say a Mercedes Benz C-class. Adding more functionality to the car like added lights, navigation system, big rim, dust pad, CD changer with these actions u are decorating the more.

In GOF own words, a decorator pattern is “Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to sub classing for extending functionality” [GoF]

[GoF] GoF, elements of reusable Object Oriented Software e-book page 149

Strategy Pattern

BLOGG 8

Strategy Pattern

At the end of the lectures on strategy patterns, I was able to understand that a strategy pattern provides a way to configure a class with one of many behaviours. Strategy pattern provides an easier way to extend a model to incorporate new behaviours without recoding the application. This pattern may be applied in a situation wherein you need different variants of an algorithm. GOF defined strategy pattern as “Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.” [GoF]

[GoF] GoF, elements of Reusable Object Oriented Software e-book page 266

Adapter pattern

BLOGG 7

Adapter pattern

From my basic understand of adapters, I was able to understand to some extent the adapter pattern too after lectures on adapter patterns. Normal adapter is used as an interface to connect another device that cannot directly fit into the other device. For example; UK made devices uses 3 pin whiles most USA devices uses 2 pin, you definitely cannot connect a three pin device into a 2 pin socket on the wall, in order to do so, you need to get an adapter that is capable of accepting the 3 pin plug to be plugged into it and it has a two pin that can enter the socket on the wall, hence it makes the incompatible device to now work, you can now use the device. There also exist adapters with 3 pins to fix into socket in a wall and has the capability for a two pin plug to fix into itself, hence providing an interface. With this brief introductory explanation of an adapter I will now attend to explain the Adapter pattern by Gang of Four. An adapter pattern creates an interface for different classes and allows them to work together. You can use an adapter pattern in the case you want to use an existing class but it interface doesn’t match the one you need. GOF, they define Adapter Pattern “Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.”

You can have a class and object adapters. An adapter pattern provides a way for clients to use two or more incompatible objects and let them communicate and interact. In general, adapter pattern improves reusability.

I now have considerable understand to what recurring problems to apply adapter pattern in designing object oriented systems.

[GoF] GoF, Elements of Reusable Object Oriented Software e-book page 20