Recent Posts

Sunday, 25 September 2016

Java Design Patterns Tutorial


     Anti-patterns are certain patterns in software development that is considered a bad programming practice. God Object is example of Anti-Pattern. Here God Object means all operations are performed only one object. For example,
class GodObject {
   function PerformInitialization () {}
   function ReadFromFile () {}
   function WriteToFile () {}
   function DisplayToScreen () {}
   function PerformCalculation () {}
   function ValidateInput () {}
   // and so on... //
}
     Here the object performed all operations. The basic idea behind object-oriented programming is that a big problem is separated into several smaller problems (a divide and conquer strategy) and solutions are created for each of them. Once the small problems have been solved, the big problem as a whole has been solved. Therefore an object need only know everything about itself.
     The opposed patterns of Anti-patterns are Designed patterns.

Design Patterns
     Which comes as a solution for real time problems of application development. A Design pattern is a general reusable solution to a commonly occurring problem within a given context in a software design.  Design patterns are considered as a good programming practice in application development or software development. For example,
class FileInputOutput {
   function ReadFromFile () {}
   function WriteToFile () {}
}
class UserInputOutput {
   function DisplayToScreen () {}
   function ValidateInput () {}
}
class Logic {
   function PerformInitialization () {}
   function PerformCalculation () {}
}
     My main intention is due to the problems faced in designing the software applications. Most of the time what happen is we design the software we implement them and by the time we ready to deliver the product to the customer. When that time client changes the requirements and due to this change of requirement then we have to do lots of changes in the code before deliver it to the customer. Due to this we face many problems as for as the implementation goes. In order to prevent these problems we use design patterns.

     Design pattern is the generic solutions to the common problems which are encountered in object oriented software design. Here very important point is changes are minimal. Patterns are language and domain independent strategies for solving common object oriented design problems. Design patterns are mainly divided into 3 types
1. Creational Design Patterns
2. Structural Design Patterns
3. Behavioral Design Patterns

1. Creational Design Patterns
     Creational design patterns are concerned with the way of creating objects. These design patterns are used when a decision must be made at the time of instantiation of a class (i.e. creating an object of a class). But everyone knows an object is created by using new keyword in java. For example:
Student s1=new Student (); 

     Hard-Coded code is not the good programming approach. Here, we are creating the instance by using the new keyword. Sometimes, the nature of the object must be changed according to the nature of the program. In such cases, we must get the help of creational design patterns to provide more general and flexible approach. There are 6 types of creational design patterns.
1. Singleton Pattern
2. Factory Pattern / Factory Method
3. Abstract Factory Pattern
4. Prototype Pattern
5. Builder Pattern
6. Object Pool Pattern

2. Structural Design Patterns
     Structural patterns provide different ways to create a class structure, for example using inheritance and composition to create a large object from small objects. Structural design patterns are concerned with how classes and objects can be composed, to form larger structures. The structural design patterns simplifies the structure by identifying the relationships. There are following 7 types of structural design patterns.
1. Adapter Pattern
2. Bridge Pattern
3. Composite Pattern
4. Decorator Pattern
5. Facade Pattern
6. Flyweight Pattern
7. Proxy Pattern

3. Behavioral Design Patterns
     Behavioral design patterns are concerned with the interaction and responsibility of objects. In these design patterns,the interaction between the objects should be in such a way that they can easily talk to each other and still should be loosely coupled. That means the implementation and the client should be loosely coupled in order to avoid hard coding and dependencies. There are 12 types of structural design patterns
1. Chain of Responsibility Pattern
2. Command Pattern
3. Interpreter Pattern
4. Iterator Pattern
5. Mediator Pattern
6. Memento Pattern
7. Observer Pattern
8. State Pattern
9. Strategy Pattern
10. Template Pattern
11. Visitor Pattern
12. Null Object

Next Tutorial  Singleton Design Pattern Tutorial

4 comments:

  1. Great article! Really very useful for developing my knowledge and I hope more valuable details
    from your post. Thanks for your good job.

    kolindia
    Guest posting sites

    ReplyDelete
  2. A IEEE project is an interrelated arrangement of exercises, having a positive beginning and end point and bringing about an interesting result in Engineering Colleges for a particular asset assignment working under a triple limitation - time, cost and execution. Final Year Project Domains for CSE In Engineering Colleges, final year IEEE Project Management requires the utilization of abilities and information to arrange, plan, plan, direct, control, screen, and assess a final year project for cse. The utilization of Project Management to accomplish authoritative objectives has expanded quickly and many engineering colleges have reacted with final year IEEE projects Project Centers in Chennai for CSE to help students in learning these remarkable abilities.



    Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining the authors explore the idea of using Java in Big Data platforms.
    Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai

    ReplyDelete