Posts

Showing posts from June, 2018

Factory Pattern from Head First Design Patterns

This post is available on: http://www.javaguides.net/2018/07/factory-pattern-from-head-first-design-patterns.html Hi, I am  Ramesh Fadatare  from India, a founder, author, designer and chief editor of a  website   JavaGuides , a technical blog dedicated to the Java/J2EE technologies.  If you like my articles/guides then connect with me directly on   Google Plus ,  Facebook ,  LinkedIn ,  GitHub , and  StackOverflow . Please comment if you have any suggestions or feedback about my articles would be appreciated. Happy learning and keep coding !!!.

Observer Pattern from Head First Design Patterns

In this post, we will learn simple Observer Pattern implementation with examples from Head First Design Patterns Book. Read more on: http://www.javaguides.net/2018/07/observer-pattern-from-head-first-design-patterns.html

Facade Pattern from Head First Design Patterns

This post is moved to: http://www.javaguides.net/2018/07/facade-pattern-from-head-first-design-patterns.html

Template Pattern from Head First Design Patterns

This post is moved to : http://www.javaguides.net/2018/07/template-pattern-from-head-first-design-patterns.html

Decorator Pattern from Head First Design Patterns

This post is moved to: http://www.javaguides.net/2018/07/decorator-pattern-from-head-first-design-patterns.html

Creator GRASP Pattern

Image
Creator  is the  GRAS Patterns (General Responsibility Assignment Software Pattern) Read about GRASP Patterns:  GRASP Patterns Overview Problem   Who should be responsible for creating a new instance of some class? The creation of objects is one of the most common activities in an object-oriented system. Consequently, it is useful to have a general principle for the assignment of creation responsibilities. Assigned well, the design can support low coupling, increased clarity, encapsulation, and reusability. Solution    Assign class B the responsibility to create an instance of class A if one or more of the following is true: ? B aggregates A objects. ? B contains A objects. ? B records instances of A objects. ? B closely uses A objects. ? B has the initializing data that will be passed to A when it is created (thus B is an Expert with respect to creating A). B is a creator of A objects. If more than one option applies, prefer a class B which aggregates or contains class A. Example  Let

Controller GRASP Pattern

Image
Controller  is the  GRAS Patterns (General Responsibility Assignment Software Pattern) Read about GRASP Patterns:  GRASP Patterns Overview Problem Who should be responsible for handling an input system event? An input system event is an event generated by an external actor. They are associated with system operations of the system in response to system events, just as messages and methods are related. For example, when a writer using a word processor presses the "spell check" button, he is generating a system event indicating "perform a spell check." A Controller is a non-user interface object responsible for receiving or handling a system event. A Controller defines the method for the system operation. Who should be responsible for handling an input event, which object/s beyond the UI layer receives interaction? Solution Assign the responsibility for receiving or handling a system event message to a class representing one of the following choices:  Represents the ov

Low Coupling GRASP Pattern

Image
Low Coupling is the  GRAS Patterns (General Responsibility Assignment Software Patterns) Read about GRASP Patterns:  GRASP Patterns Overview Problem How to support low dependency, low change impact, and increase  reuse? Solution Assign responsibilities so that coupling remains low. Try to avoid  one class to have to know about many others. Key points about low coupling Low dependencies between �artifacts� (classes, modules, components). There shouldn�t be too much of dependency between the modules, even if there is a dependency it should be via the interfaces and should be minimal. Avoid tight-coupling for collaboration between two classes (if one class wants to call the logic of a second class, then first class needs an object of second class it means the first class creates an object of the second class). Strive for loosely coupled design between objects that interact. Inversion Of Control (IoC) / Dependency Injection (DI) - With DI objects are given their dependencies at creation ti

High Cohesion GRASP Pattern

Image
High Cohesion is the  GRAS Patterns (General Responsibility Assignment Software Pattern) Read about GRASP Patterns:  GRASP Patterns Overview Problem How to keep classes focused, understandable and manageable? Solution Assign responsibilities so that cohesion remains high. Try to avoid classes to do too much or too different things. The term cohesion is used to indicate the degree to which a class has a single, well-focused responsibility. Cohesion is a measure of how the methods of a class or a module are meaningfully and strongly related and how focused they are in providing a well-defined purpose to the system . A class is identified as a low cohesive class when it contains many unrelated functions within it. And that what we need to avoid because big classes with unrelated functions hamper their maintaining. Always make your class small and with precise purpose and highly related functions. Key points about  high cohesion  The code has to be very specific in its operations.  The res

Information Expert GRASP Pattern

Image
Information Expert is the  GRAS Patterns (General Responsibility Assignment Software Pattern) Read about GRASP Patterns:  GRASP Patterns Overview Problem What is a general principle of assigning responsibilities to objects? A Design Model may define hundreds or thousands of software classes, and an application may require hundreds or thousands of responsibilities to be fulfilled. During object design, when the interactions between objects are defined, we make choices about the assignment of responsibilities to software classes. Done well, systems tend to be easier to understand, maintain, and extend, and there is more opportunity to reuse components in future applications. Solution Assign a responsibility to the information expert - the class that has the information necessary to fulfill the responsibility. Example   Let's consider Point of Sale (POS) application: a Brief overview of POS application. Application for a shop, restaurant, etc. that registers sales. Each sale is of one

GRASP Patterns Overview

Image
What are GRASP Patterns? They describe fundamental principles of object design and responsibility assignment, expressed as patterns.  After identifying your requirements and creating a domain model, then add methods to the software classes, and define the messaging between the objects to fulfill the requirements. The GRASP patterns are a learning aid to help one understand essential object design, and apply design reasoning in a methodical, rational, explainable way. This approach to understanding and using design principles are based on patterns of assigning responsibilities. Responsibilities and Methods The UML defines a responsibility as "a contract or obligation of a classifier". Responsibilities are related to the obligations of an object in terms of its behavior. Basically, these responsibilities are of the following two types: knowing doing Doing responsibilities of an object include: doing something itself, such as creating an object or doing a calculation initiating