Saturday, 16 July 2022
Tuesday, 5 February 2019
Creational | Factory method design pattern
Principle:
"Separate out the codes which are subject to change and not subject to change"
Manager (talks to) -> Factory (creates) --> Objects
Factory method:
That method, which has the logic of creating the object based on some certain criteria, are calls "factory method"
Advantage:
1. Avoid code duplication by reusing the creational logic.
2. Separate changing logic vs non changing logic
3. OCP, principle applied
Abstract factory method
MembershipManager (has some concrete policy as general and abstract method for subclass to implement based on region)
LondonMemborshipManager , NYMembershipManager
Behavioral | Strategy design
Motivation:
While you design a inheritance hierarchy to handle different type of things like
Network devices.
and you find slowly that each NE, has some common behaviour and also some different behaviour.
you also find that, for some types of NE, you are required to provide empty implementation.
you find that , with new requirements you are forced to touch the methods/behaviour of existing code.
then you need to do following
1. separate interfaces for different types
2. as much as possible create more types of behavioural implementation,
like rebbotable device, repluggabe, nonStoppable, manually Stoppable, autoStoppable, reconfiguration, autoReconfigurable, manualReconfigurable, Updatable,timeUpdatable, versionUpdatable.
3. and then composition this behaviour(object) inside your Network element object.
like OME(with autoupgradable).
so when u create that OME type of NE, you also create autoupgradable object ( behaviour ) and pass to constructor.
so you encapsulate the behaviour .
PROGRAM TO SUPER TYPE
that means , you have a placeholder for plugganle/stoppable etc types of super type interfaces insidr NE class,
and later at runtime you can create and subtype object and assign.
Monday, 5 December 2016
Creational | Factory patterns
Benifits
Old user
Phone phone = new Iphone();
phone.start();
Or
Phone phone = new Windows();
phone.start();
So now
Phone phone = PhoneFacotory.getPhone("Iphone");
Benifit,
Suppose if you change the Class name
Monday, 7 November 2016
Creational | Builder Patterns
Where we deal with the ways to create Objects
1. Builder
Here you can create don't have to supply all the "contructor" argument, you can still create a object with single or more parameters
Like say , Object to be created has constructior like below
Book( String title, String author, String pubDate)
But we provider a
BookBuilder which will have default value for other arguments and set if passes but thr way they create Book will change.
But orginal Book class need not change
BookBuilder {
String title,author,pubDate
public BookBuilder setTitle(String title) {
this.title = title;
return this.
}
//Similarly others setter
public getBook()
{
Book book = new Book (title,author,pubDate);
}
//User
Book book = new BookBuilder().setTitle("walla").setAuthor("Habibi").getPhone(),
//This will create Book with only two mandatory parameters

