Design Patterns

How to Write Good API

 1– methods should do only one operation (only one function per method) this enable -code reuse -modularity -sample for testing 2– keep method small if method have to make more than function you can encapsulate them in object 3– defensive Programming check on expected arguments to method Ex.- If not null – should be string… Continue reading How to Write Good API

Design Patterns

Visitor Design pattern

the visitor design pattern is a way of separating an algorithm from an object structure it operates on. A practical result of this separation is the ability to add new operations to existing object structures without modifying those structures. It is one way to easily follow the open/closed principle. the visitor allows one to add… Continue reading Visitor Design pattern

Design Patterns · java

strategy design pattern

public interface Sender { public boolean Send(NotificationBean notificationBean,List … temp); } public abstract class sendEmailTemplate implements Sender { public abstract void preSend(NotificationBean notification,List … temp); public abstract void PostSend(); public abstract boolean TryToSend(); public abstract boolean IsSent(); public abstract boolean NotifyDB(boolean success); public boolean Send(NotificationBean notification,List … temp) { preSend(notification,temp); if (TryToSend() && IsSent()) PostSend();… Continue reading strategy design pattern

Design Patterns · java

Abstract Factory Design Pattern

1-This pattern is one level of abstraction higher than factory pattern. 2-the abstract factory returns the factory of classes. Like Factory pattern returned one of the several sub-classes, this returns such factory which later will return one of the sub-classes. 3-we need to get the specification of various parts of a computer based on which… Continue reading Abstract Factory Design Pattern

Design Patterns · java

Factory Design Pattern

if we have a super class and n sub-classes, and based on data provided, we have to return the object of one of the sub-classes, we use a factory pattern. Example: Let’s suppose an application asks for entering the name and sex of a person. If the sex is Male (M), it displays welcome message… Continue reading Factory Design Pattern

Design Patterns

Design Pattern

Introduction Instead of defining what is design pattern lets define what we mean by design and what we mean by pattern. According to me design is blue print or sketch of something so it can be defined as creation of something in mind. Moving to pattern, we can define it as guideline, or something that… Continue reading Design Pattern

Design Patterns

Strategy Design Pattern

Lets say your in the military and are charged with defending a country. A top general tells you that you need to design a computer system that will activate the military when an invasion happens. You might begin to layout your code like this: public abstract class Military {     public void defend()     {         System.out.println(“The military… Continue reading Strategy Design Pattern