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