Jun 29, 2008

One for new bloggers

by
A nice blog for all new googlers. Gives useful informations and hacks on how to create effective blogs and to monetize your existing ones.
I liked it.

Jun 19, 2008

Factory Method

by
In this design pattern, a contract is defined for creating an object. All derieved classes who implements this policy(via virtual method or implementing an interface ) decide which object in a class heirarchy to instantiate.

class Creator
{
  virtual MyObject CreateObject();
}


Creator defines a contract that all its derieved classes expose a method "CreateObject" which should return an object which "IS" a MyObject.


class MyObject
{
..
..
}
class MyConcreteObject : MyObject
{
..
..
}
class MyOtherConcreteObject : MyObject
{
..
..
}


MyConcreteObject and MyOtherConcreObject are different flavour of MyObject.Each of the class share IS relationship with MyObject.
Let's implement few "Creators".



class
MyConcereteObjectCreater : Creator
{
  virtual MyObject CreateObject()
  {
     return new MyConcreteObject();
  }
}


class
MyOtherConcereteObjectCreater : Creator
{
  virtual MyObject CreateObject()
  {
    return new MyOtherConcreteObject();
  }
}

Now the module which requires different flavours of MyObject need not worry about the instantiation of MyObject. It delegates the responsibility to "Creator" classes and they decide which type of MyObject is created.



void
SomeMethod(Creator bClass)
{
  MyObject myObject = bClass.CreateObject();
  // MyObject is specific to a particular Concrete Class
}


Advantages of Abstract Method:

  • Factory methods gives a hook for providing an extended version of an object.
  • Connects parallel hierarchies (MyObject --> Creator)

Jun 17, 2008

Creational Patterns

by
Creational design patterns abstract the instantiation process. Introducing this design patterns makes a system independent of how its objects are created and composed.
Two major responsibilities of Creational patterns are:
  • To encapsulate the concrete classes that system uses.
  • To encapsulate how instances of these classes are created.

Factory Method: Creates an Instance from a several derieved classes

Abstract Factory: Creates Instance from several family of related classes.

Builder: Separates object instantiation from object representation.

Prototype: A single object is copied and cloned.

(.. to be continued in detail )

Jun 7, 2008

Common Software Design Blunders

by
I have been reviewing some of the codes at work (mostly my own ;) ).We make lots of " mind numbingly stupid" mistakes when designing a software, only to regret later.Here are my favourite ones.

Explicit object Instantiation: If your design involves instantiating objects from concrete classes, then there's a flaw already.This commits an application to a particular implementation instead of a particular interface , it complicates future (unavoidable) changes.

Visibility to (Server) Object Implementation: If a client module knows how an object is represented or Implemented, it tends (rather unknowningly) to a design which is more specific to object's implementation.Hiding this information from client is better design because even if implementation of the object used is changed or altered, there are no cascading changes on the client.

Algorithmic Dependencies: Algorithms are prone to changes in the name of optimization and often are replaced with better ones. Objects that depend on an algorithm will have to change whenever algorithm changes. Therefore algorithms that are likely to change should be isolated from rest of the lot.

Too much SubClassing: Subclassing requires an in-depth understanding of the parent class. Overriding one method might require overriding another and so on.Different ways of object composition would be a better approach than extending functionality by subclassing.

Top Ad 728x90