Sunday, April 29, 2007

Anti Patterns

What is an Anti Pattern

Anti pattern is commonly occurring solution to a problem that generates decidedly negative consequences.It provides a common vocabulary for identifying problems and find solution. It provides real world experience in recognizing recurring problem in the software industry.

It serves two important solutions for software engineering. It helps to identify the problem and help to implement the solution.

The following diagram represent how anti pattern works.


  • The context and causes mean the problem definition,it describe the problem to identify the problem.
  • After it goes to antipattern solution.
  • The symptom and consequences of the diagram are assessed the Antipattern solution, and implement the refactored solution.
  • The refactored solution resolve and rengeeneering into a more beneficial form.

Template of Documenting Anti Pattern
Anti pattern has template as desing patterns.

Name - Antipattern name

Description - What is the debatase desing

Consequences - Harmful results of bad design

Detection - How it find it

Improvement - How to find it or avoid or it.


References

Anti Patterns-Refactoring Software,Architectures,and project in Crisis.

William H.Brown,Raphael C.Malveau,Hays w.McCormick / ISBN - 0-471-19713-0

Friday, April 27, 2007

Strategy Pattern

Stategy Pattern

Strategy is one of behavioral pattern in pattern categorisation.Strategy pattern,i have to apply in my couse work first question.

What i learnt about Strategy Patttern

Startegy pattern encapsulate family of alogrithm and make them interchangable.It make alogrthm changable independently from client that use it.




The above diagram describe the structure of the design pattern.

Participants

Here are the participants support to strtegy pattern.

Context

It maintain a reference to a strategy object and configure with a ConreteStrategy object.

ConcreteStrategy

Impliment the alogrith using strategy interface.

Strategy

Declare interface common to all supported alogrithm.

Advantages of Strategy Pattern

  • It make very easy changing behaviors.Client just need to change strategy.
  • Stategy pattern make easy to use several behavior alogrith instead of making several objects to several behaviors.
  • Its very simple task if we want to change or remove any of behavior using strategy pattern.
  • iIt redue using of several classes by reducing many objects into one class.

Referances

1.Data and Object factory /

http://www.dofactory.com/Patterns/PatternStrategy.aspx

2. Strategy Design Pattern

http://www.exciton.cs.rice.edu/JAvaResources/DesignPatterns/StrategyPattern.htm

Thursday, April 26, 2007

Creationa Pattern-Factory

Creational patterns are dealing with object creation machanism,which trying to create object to find a good solution.It allow programmers to write methods that create new object without explicity using the new operator in software engineering.The factory method is a one of the creational pattern.

What is factory method ?

The factory pattern method defines an interface for creating an object,but lets subclasses decide which class to instantiate.

!!! Use of factory method gives programmer oppertunity to abstract the specific attributes of an object into specific subclasses which create them.

The following diagram show the structure of the factory method.

Structure




Paticipant of the Factory Method

Product
The product define the interface of type of object which factory method creates.

Concrete Product
Implement the product interface

Creator
It define the factory method.Its class that contains the implementation for all of the methods to manipulate products.

Concrete Creator
Override the factory method to return an instance of a ConcreteProduct.It responsible for creates one or more concrete products.It has knowledge how to create these products.


What i learnt about Factory Pattern
  • Allow subclasses to choose which type of object to create.
  • Factory method make code more flexible and extensible,because it allows to program and design interface not implimentation in changing code.
  • It avoid duplication of code and provide one place to perform maintanance ,by placing all creation code in one object or method.

Related Pattern

Abstract Factory-

Factory method is useful for impliment individual object for specific purpose without the developer knowing class being instantiated.The Abstract factory is usefull when someone need to create a matched set of bjects rather than individual object.

Prototype-
The prototype pattern provides an alternative way for an object to work wtih other object.

References

Head first Design patterns/Eric Freeman & Elisabath Freeman

ISBN-0-596-00712-4


Tar bob/Factory patterns ,Factory method, and Abstract Factory,
http://www.research.umbc.edu/~tarr/dp/lectures/Factory.pdf

Wednesday, April 18, 2007

Behavioral Pattern-Adapter

There are two kind of the adapters in adapter pattern.Those are Object adapter and Class adapter.This two kind of adapters give two different meaning for adaptee and adapter.

The follwing diagram helped me to understand about the difference between two of them.

Class Adapter


Client
  • The Client class call to Target class.
Adapter

  • The Adapter extend both classes.It can take target method calls and turn around method on adaptee.But Adaptee class does not have same method.
  • There are some more advanage of adapter class.The adapter class is commited to one specific adapter class.
Adaptees

  • The class adapter doesn't need to implement entire adaptee class, because adapter class inherit adaptee class and it also sub class of the adaptee.It also overide behavior of adapter.
Comparing to object adapter class adapter require less code than object adapter.

Limitation

  • Less flexible than object adapter
  • its very tough for single inheritance.
Object adapter









  • One advantage of the of object adapter is its more flexible than class adapter.
  • It work with adaptee and all of subclasses.
Limitation
  • It reuqire more code to implement than adapter class.

Rerefences

  1. Davis Guy/Zhou Ming,Java native interface(JNI)/SENG 609.04 Desing Patterns-2003/http://www.guydavis.ca/projects/presentations/adapter/adapter.ppt#271,16,References
  2. Whitney Roger/CS 635 Advanced Object Oriented Desing and Programing/San Diogo State University - 2001 - http://www.eli.sdsu.edu/courses/spring01/cs635/notes/proxy/proxy.html#Heading10.

Behavioral Patterns-Adapter

Adapter Pattern

As a student of PAFSD,this week i try to understand about the adapter pattern which will helpful for my coursework first question. After read a "Head first design pattern book and related websites i understood valuable information about adapter pattern help for software development.

What i learnt about this Pattern

The adapter pattern allows classes work together, which have incompatible interfaces in system. It acts as a middle man by receiving request from the client and converting them into request that make what exactly client expect. In software re-engineering or reuse process, some times we meet incompatible interfaces to join each other to run system.

The main reasons for this problem are took kit or class libraries are incompatible with interface with new system. Then software developer use adapter to create reusable class that corporate with incompatible interfaces to get exception interfaces. The following definition is the most understandable definition for me about the adapter pattern.

The following definition is the most understandable definition for me about the adapter pattern.

The Adapter Pattern

"converts the interface of a class into another interface the clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces".
Head First Design Patterns- ISBN 0-596-00712-4

!!! When i was considering about the above things, i had question about adapter pattern.

What happen the systems have old system interface and new system interface? Its bit confusing to create a adapter pattern.

Further reading about the Head first book i realised we can create two way adapter to solve a this problem.The two way adapter supports both interfaces to match old vender class and new vender class.



Following link will give you good idea about the Adapter pattern.
http://www.research.umbc.edu/~tarr/dp/lectures/Adapter-2pp.pdf.

Monday, April 16, 2007

Structural Pattern-Decorator

April 16 and 17

When i was studying about the decorator pattern further,i have realised lot of valuble things are included in pattern language for software developers.

Another important fact about decorator pattern is,it shows to add responsibilites to individual objects dynamically without affecting other objects.


The following example will show how it happen.

This example is based on the windows system.We assume windows are representing by instances of widows class .To allow scrolling the windows form,must contain horizonal or vertical scrollbars.The windows class has no functionality for adding scrollbars and borders.Using decorator pattern we use subclass called decorator to add functionality to existing windows object.According to following diagram,textview class and decorator are subclasses of the windows.
As i explained earlier it will add responsibility to individual object without affecting or changing any other objects.



Why we cannot use Inheritance?

As above diagram,suppose we have a text view GUI component and it would be added with different kind of borders and scrollbars to complete windows form. There are two borders called plain borders and 3Dborders and two scrollbars called vertical and horizonal.The borders and scrollbars are subclasses of decorator.

Using the inheritance we need to make lot of subclasses to represent text view for all cases.
example-text view-plain
-text view-plain vertical
-text view-3D
-text view-3D horizanal

Without making more subclases ,we can use decorator pattern to mix and match decorators any way we like.Decorate pattern has same super type as the object they decorate.We can use one or more objects to wrap an object.

Related Patterns

Strategy

The decorator pattern allow variable behavior before or after the properties,functions,of another object are called.If developer wants to arrang for things to happen in the middle of calls to properties,funcitons or subroutines can use strategy pattern.

Template Method

The template method allow variable behavior in the middle fo a function or subroutine call instead of before or after it.The decorator

Filter

The filter pattern is focus on manupulating a data stream.Its a specialised version of the decorator.

References

Visual Basic Design Patterns / Mark Grand, Brad Merrill / Wiley Publishing inc /ISBN - 81-265-0614-8

Monday, April 09, 2007

Structural Patterns-Decorator

Decorator Pattern

"Attaches additional responsibilities to an object dynamically.Decorates provide a flexible alternative to subclassing for extending functionality"
Head first Design patterns- ISBN 0-596-00712-4

The following class diagram will help to understand the decorator Patterns.

Participants

Component

Each components can be wrapped by a decorator.

Decorator

The Decorator always has component,which means the decorator has an instance variable that holds a reference to a component.

ConcreteComponent

The concreteComponent objects dynamically add new behavior to component.That mean the ConcreteComponent is extending the component class.Genarally it is call inheritance. The inheritance is using for this as type matching.It can not be used to get behavior.

The ConcreteComponent can add new behavior to component by composing decorator with comopents.The new behavior can be added by composing object together rather than inherit form a super class.


ConcreteDecorator
The ConcreteDecorator has an instance variable for the thing it decorate.


What i learned about Decorator Pattern?

The first time i have learned about the object composition.That show how to match and mix components.(According to diagram can match and mix ConcreteComponent and ConcreteDecorator) i knew only about the inhertance,Befor i learned the decorator pattern.

  • In the object composition can implement new decorators at any time to add new behavior.
  • Using inheritance we need to change existing code according to new behavior.
  • using inheritance,inherit only what ever behavior the superclass gives or override.In this composition we can mix and and match decorator in runtime.
  • We can wrap a component with any number of decorator in decorator pattern.
  • It provides an alternative to subclassing for extending behavior.
    The ConcreteDecorator has an instance variable for the thing it decorate.

Saturday, April 07, 2007

Patterns in Software Development

April 2

Patterns for software development

Desing Patterns are very useful for software implementation,reengineering and reuse।As a fledging software developer and design patterns student,im very interesting to understand about the design patterns and learn how they can use software engineering.


Types of Design Pattern

The Gang of four (GOF) are founders of the software design patterns.According to them ,there are three catogories of software design Pattens.These are

  • Creational Patterns
  • Structural Patterns
  • Behavioral Patterns

Creationa Patterns

Creational Patterns are dealing with object creatation machanism,which trying to create an objects to find a suitable solution.The Creational pattern solve the problem by controling the object creation which gives result in basic form of object creation.

  • Abstract Factory
  • Builder
  • Factory method
  • Prototype
  • Singleton

Behavioral Patterns

Behaviroal patterns identify common communication patterns between objects and realized patterns.

  • Adapter
  • Builder
  • Composite
  • Decorator
  • Facade
  • Flyweight
  • Proxy

Structural Patterns

Structural Patterns show how classes and objects are composed into larger structure.

  • Chain of resp
  • Command
  • Interpreter
  • Iterator
  • Mediator
  • Memento
  • Observer
  • State
  • Strategy
  • Template Method
  • Visitor

*Design Patterns-Data and object factory-http://www.dofactory.com/Patterns/Patterns.aspx
.

What is a pattern ?

April 1

What is a pattern ?

During late 1970,Alexander Christoper and his collegues were introduced architecture patters to solve the design problem in building architecture. This was the first discover about the pattern language which we are using many fields every day for resolve problem.


Some Definition for patterns?

This is Alexander's definition about patterns

"Each pattern describes a problem which occurs over and over 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"

Christoper Alexander - A Pattern Language:
Towns/Buildings/Construction 1977,New York:
Oxord University Press

Consequently his methods have used to many different fields such as design patterns uses in software engineering and pedagogical patterns in education. The design patterns, let designers easy to capture the body of knowledge and understand about good system architecture that meets the need of customers.

What are patterns not ?

-Patterns are not untested theories
-This is not a solution,which some one have worked once.This is a best Solution for occuring problem.
-Its applicable to every Context.

*Introduction to patterns- Dr.M.G.Srikanthan-Class Notes-2006 feb