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.
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of About GRASP Principles

  • Rails will be a Model split according to the functions of management

    In the development of Rails applications, with the expansion of business, Model code of increasing volume, (originally in the Rails also said thin Controller, Fat Model, is not it?), Hundreds of thousands of lines of code is also very common Therefor ...

  • Hibernate performance tuning (the focus of understanding)

    1. Object Cache: fine-grained, in view of the table Record Level, transparent access, without changing the procedure code can greatly enhance the performance of web applications. ORM object cache is a magic weapon for the victory. 2. The merits of th ...

  • IBM Ajax Tutorial Series

    Links: http://ibm.csdn.net/ISN_J.aspx?action=JMP&pointid=1550 Part 10: Using JSON for data transmission In the asynchronous application to send and receive information, you can choose to plain text and XML as data format. Ajax grasp of this issue ...

  • Hundred software developers interview question

    Hundred software developers interview question Think employed to engage in software development of smart people is not easy. The event of accidentally, it will get a pile of low-energy large baboons. I met last year on this matter. You certainly do not wa

  • Software development sunflower Baodian [reprint]

    Master the ability to reuse code very familiar with the new API's fast. This is because, he once used a lot of the API, have a lot of reusable code. He knows what is available and what is deficient. He has been using Qt, also used by gtk +, also used

  • Object-oriented design principles 11

    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 objec ...

  • [Reprint] Java professionals required books and list of sites

    Concurrent Programming in Java: Design Principles and Patterns (Doug Lea) Concurrent Programming in Java: Design Principles and Patterns, 2nd edition (Doug Lea; Addison-Wesley, 1999 years) Java Concurrent Programming - Design principles and patterns (seco

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries