About GRASP Principles

GRASP (General Responsibility Assignment Software Pattern) is a universal duty software distribution model. GRASP is the core of their own be able to do it yourself, just do your own thing, that is, distribution of responsibilities and the achievement of high cohesion. Object-oriented design is used to solve some of the problems. GRASP put forward nine principles, the following nine design principles that I will set out to do 11.

High cohesion, low coupling (High Cohesion, Low Coupling)

In the object-oriented programming design, as small as a class as large as a functional module, if the dependency between them is high throughout the software development will entail all sorts of obstacles. For example: When you modify a class or a particular time of a module, the corresponding changes you want to rely on others with similar classes and modules, making programs difficult to maintain; code will become difficult to understand, a single operation, will involve a lot of programs between the call; process even more difficult to reuse, when you want to reuse a class, when corresponding with them want to rely on the class or method will also be added one after another to come.

This is why we should follow this principle of reason, and high cohesion and low coupling are often accompanied with emerge. Low coupling is actually two classes or the degree of close links between modules and high cohesion is the class methods and methods of responsibilities between the correlation. To avoid low-cohesion, high coupling, the solution is not only to reduce the class because of a change in the impact of another class, but also maintain the class or module is focused, understandable, manageable and support low coupling, which is more accurate to a class or module allocation of responsibilities.

High cohesion and low coupling is a software development the most important principle, grasp the other models is also based on high cohesion and low coupling principle-centered.

Information specialists (Information Expert)

How to achieve high cohesion, that is how the allocation of responsibilities to the class? We should follow the principles is to have the responsibility to complete the duties assigned to that class of information.

Creator (Creator)

How to allocate the responsibility to create an object then? Principle is that when the following conditions are met (for the better), from B to create A:
1.B frequent use of A
2.B contains or aggregation of A

To give a simple example, if class A implements interface B, class C, D is a class A, an attribute, then the C, D should be from A to create, A should be B to create. If the C, D from B to create, then when the C or D to change the time, B and A have to follow the changes, greatly enhancing the B, C, D of the coupling between the degrees, contrary to the principle of low-cohesive. Popular point that is, if B used in the A, then B should be to create an A, rather than by the other classes to create.

Controller (Controller)

In the UI layer, it should be handled by the class to which the system operation? Principle is that the system of handling the incident responsibilities assigned to the controller class, this is equivalent to MVC controller class in C. The system event controller class is usually control of Letting Them Go class of use cases.

Polymorphism (Polymorphism)

According to the type of behavior change with the definition of responsibilities should be assigned to whom?

To give a simple example, traveled to Guangzhou, car be considered a behavior, but this behavior can be changed, such as travel by plane, by car or train, then ride the definition of the act should be assigned to whom?

Through multi-state operation principle is based on the type of variable to the definition of acts of responsibilities assigned to the occurrence of the behavior of the class. JAVA is the place to implement them define a car's interface, and then the specific travel by plane, by car or train a class of behavior are defined to implement this feature, and then let the class to achieve three specific car interface.

Pure fiction mode (Pure Fabrication)

The non-problem areas of responsibility should be assigned to whom?

We are in the design of the class time, often as much as possible to maintain and real-world objects were the same, then we abstract from the real world object is called out of class issues in the field of class, then when we save this time to operate a database object operation database is a non-existence of real-world business objects, he is the non-problem areas of responsibility.

This allocation of responsibilities between the principle of non-problem areas is the distribution of responsibilities to the artificially generated classes. Problem areas such as the class is usually placed inside the PO, he should not include CRUD operations and so on. Well CRUD these operations should be put an artificially generated is what we in the business logic outside of the addition of a class.

Indirect (Indirection)

Two or more things in order to avoid direct coupling between the, how should the allocation of responsibilities?

Design principles is the duty assigned to the intermediary object. For example, class A and class B is a many to many association relationship, when the A time for a change, B needs to do the appropriate changes, when the B time for a change, A change needs to be done accordingly, it is a violation of the principle of low coupling, the solution is inserted between A and B a C class, class C properties that only A and B, with C to record the relationship between A and B, when A want to use a B or B to use A when they come through C call each other.

Prevention of variation (Protected Variation)

How to design objects, systems and subsystems, so that the internal instability does not change or adversely affect the other elements?

Is expected to identify the factors of instability, creating stability in its external interface. For example: by car by car to Guangzhou is one among the factors of instability, the future may be by plane or train, then we must take out a car car abstraction interface, when one day want to ride the train when the direct additive an implementation of the class on it.

分类:Java 时间:2008-07-25 人气:375
blog comments powered by Disqus


  • The Open-Closed Principle (OCP) - OO design principles of open and close 2010-07-31

    The Open-Closed Principle (OCP) - OO design principle of opening and closing: Software entities (classes, modules, function, etc.) Should be open for extension, but closed for modification. Software entities (modules, classes, methods, etc.) should b

  • GRASP design principles 2010-07-24

    GRASP (General Responsibility Assignment Software Pattern) is the common duty software distribution model. GRASP is the core of their able to do it yourself, just do their own thing, that is, distribution of responsibilities and to achieve high cohes

  • Some software design principles 2011-05-23

    Don't Repeat Yourself (DRY) DRY is a simple rule, and most easily understood. But it is probably the hardest applications (because to do so, we need to do in the generic design of considerable efforts, this is not an easy task.) It means that when we

  • SOA service design principles - reproduced 2011-08-24

    This section is a guide for the entire SOA system, represents the establishment of the system in all aspects of decision-making needs. You will design and implement personnel rules and guidelines which should be provided? Your SOA infrastructure will

  • Go Object Oriented Design 2014-11-06

    Go hastypes and valuesrather than classes and objects. So can a language without classes or objects be object-oriented? While Go may not fit the typical mold of an OOP language, it does provide many of the same features, albeit in a slightly differen

  • Object-oriented design principles 11 2009-02-28

    What is object-oriented design? Contains what? The benefits of it are what? Required to pay what you do? In today's age, ask these questions seem to be foolish, because this year almost every software developer knows how to use some sort of object-or

  • Object-oriented design principles 2009-08-26

    Design patterns are all different packaging variability, thus allowing the system to achieve different angles in the "open closed principle" requirement. Software systems in software, a modular design of the main well, the most important sign is

  • oop design principles 2010-11-12

    A principle of opening and closing 1 What is the principle of opening and closing Switching principle is object-oriented design "reusable design" is the cornerstone of object-oriented design is one of the most important principles, principles ar

  • Object-oriented software design principles 2009-08-03

    Excellent object-oriented software should be designed to achieve the following four objectives: Maintainability Maintainability: the new design requirements to allow a more easy and smooth manner into the system has to, and maintenance work can be ea

  • Bill Venners a dialogue with Martin Fowler (design principles and code ownership) 2010-03-29

    Dialogue Martin Fowler (Martin Fowler) - Part II: Design Principles and Code Ownership Profile This part of the interview, Fowler discusses some design principles, including how to avoid repetition, how to separate business logic and its said that ex

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 闽ICP备15018612号

processed in 0.170 (s). 12 q(s)