Following are design pattern :
1. MVC Architecture.
2 Factory Architecture.
3. Singleton Architecture.
1.Focus on MVC.
- MVC : used for Stand alone application means of Desktop base application.
- M : Model : Displaying the data.
- V : View : Rendering the content of Model.
- C : Controller : Inereacting with user interface with view in to action that will perform update on Model.
2.Focus on Factory :
- Factory Method is a creational pattern.
- The Factory Pattern is all about "Define an interface for creating an object, but let the subclasses decide which class to instantiate. The Factory method lets a class defer instantiation to subclasses".
- factory is not needed to make an object. A simple call to new will do it for you.
- We having super class and n number of subclass ,based on data ,we need to return one of subclass object.
- In Factory Pattern an interface is responsible for creating the object but the sub classes decides which class to instantiate. It is like the interface instantiate the appropriate sub-class depending upon the data passed.
Run Time Example :
public class MammalsFactory {
public static Mammals getMammalObject(String name) {
if (name.equalsIgnoreCase("Cat")){
return new Cat();
} else {
return new Dog();
}
}
} Now if you see this class, here we will be passing an argument to
the getMammalObject function based on the argument passed we return the
Mammals object of the class.public abstract class Mammals {
public abstract String doWalking();
} Here we have created an abstract class Mammals. This class will be used by the Dog and Cat class.public class Cat extends Mammals {
public String doWalking() {
return "Cats has been Informed to perform Walk Operation";
}
}Here we have created Cat class, this class extends from Mammals
class so it is understandable that Cat needs to have the implementation
for doWalking() method.public class Dog extends Mammals {
public String doWalking() {
return "Dogs has been Informed to perform Walk Operation";
}
}Here we have created Dog class, this class extends from Mammals class
so it is understandable that Dog needs to have the implementation for
doWalking() method.public class FactoryClient {
public static void main(String args[]) {
MammalsFactory mf = new MammalsFactory();
System.out.println(mf.getMammalObject("Dog").doWalking());
}
}Here if you see i want to create an object for Dog class and for
that we are not directly loading the Dog class. Instead we are
instantiated the object for MammalsFactory class.
For more clarification let me know...
No comments:
Post a Comment