Re-engineering -- object-oriented design principles -- s.o.l. I. D Design Principles

Source: Internet
Author: User

SRP-single Responsibility Principle
    • Full name: single Responsibility Principle
    • Definition: the definition of each context object (class, function, variable, etc.) should only contain a single responsibility
    • Description: objects are highly encapsulated with a single responsibility. Changes to objects depend only on changes to a single responsibility. They are defined based on high cohesion in software design.
    • Source: Robert C. Martin (Uncle Bob )《Agile Software Development, principles, patterns, and practices"2002
    • Source: Tom Demarco 《Structured Analysis and systems SpecificationProposed cohesion 1979
    • Declaration: to make our classes more robust! A class shoshould have only one reason to change!
OCP-open-closed Principle
    • Full name: open-closed Principle
    • Definition: context objects (classes, modules, functions, etc.) should be open to extensions and closed to modifications.
    • Description: uses the object-oriented polymorphism (polymorphic) to flexibly handle changes and embrace changes.
    • Implementation: 1: Abstraction and inheritance; 2: interface-Oriented Programming
    • Source: Robert C. Martin (Uncle Bob )《Agile Software Development, principles, patterns, and practices"2002
    • Declaration: Protecting changes and embracing changes
LSP-liskov replacement principle
    • Full name: liskov substitusion Principle
    • Definition: A parent object can be replaced by a quilt object.
    • Source: US first PhD in Computer ScienceBarbara liskovProfessor and Professor Jeannette Wing at Carnegie Mellon University proposed in 1994
    • Scenario: behavior subtype, type abstraction, and inheritance. Design class abstraction, inheritance and Polymorphism
    • Implementation: inversion of parameters (passed in) and covariance of returned (outgoing)
    • DESIGN: contract-based design mode (Code contract of. NET Framework 4 seems to be another thing ?)
      • Preconditions: the preconditions cannot be reinforced in the subclass.
      • Post condition: the post condition cannot be weakened in the subclass.
      • Invariant: the Child-type invariant must be stored in the Child-type.
    • Meaning: how can we design object type inheritance and interfaces (parameters and return value types)
    • The following is an example of a violation of the liskov replacement principle:
      Static void drawshape (shape s) {If (S is rectangle) drawrectange (S as rectangle); else if (S is square) drawsquare (S as square ); else {//...}}
ISP-interface separation principle
    • Full name: interface segregation principle
    • Definition: users should not be forced to rely on methods they do not need
    • Description: separates large coarse-grained interfaces into small-grained interfaces with clear specifications.
    • Meaning: loose coupling facilitates reconstruction Iteration
    • Interface: interface-oriented programming to reduce dependencies
    • Source: Robert C. Martin (Uncle Bob )《Agile Software Development, principles, patterns, and practices"2002
Dip-Dependency inversion principle
    • Full name: Dependency inversion principle
    • Definition: dependent on abstraction, not on specifics, because abstraction is relatively stable
    • Application: decoupling in applications through dependency Injection
      • Advanced modules should not depend on low-level modules. Both of them should depend on abstraction.
      • Abstraction should not depend on implementation details. Implementation Details should depend on abstraction.
    • Meaning: Reuse low-level modules, reuse implementation, and remove Dependencies
    • Implementation: through interfaces or abstract classes
    • Others: plugin, service locator, or dependency Injection
    • Source: Robert C. Martin (Uncle Bob )《Agile Software Development, principles, patterns, and practices"2002

Re-engineering -- object-oriented design principles -- s.o.l. I. D Design Principles

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.