Understanding strategy pattern by designing game of chess

Today we will try to understand Strategy Pattern with the help of an example.
The example we will consider is The Game of Chess. The intention here is to explain strategy pattern and not to build a comprehensive Chess Game solution.

Strategy Pattern : The Strategy pattern is known as a behavioural pattern – it’s used to manage algorithms, relationships and responsibilities between objects. The main benefit of strategy pattern is to choose the algorithm/behaviour at runtime.

StrategyPattern

Lets try to understand this by implementing this to design the chess game.

Read More »

Difference between Factory and Abstract Factory

The main difference between the two is Inheritance vs Composition.
Abstract Factory uses composition whereas Factory like template uses inheritance.

Abstract factory pattern can use factory method to actulay implement different types of object creation, but it is not necessary.

I would say Abstract Factory Pattern is more into design product creations and how different variants of the product would be created , it is to supply a “kit” to create product and its different variants. It may use prototype/factory method and other builder pattern inside when actualy instantiating the object.

So In Abstract Factory Pattern ,we would provide an interface of product which can be used to create its families without specifying their concrete implementations. Lets try to understand this by example.
Read More »