C # design pattern: Six design principles

Source: Internet
Author: User

The typical object-oriented principles can be divided into two categories: class-oriented and package-oriented.

Class-oriented includes: srp--single responsibility principle.

ocp--Open closure principle.

LSP--The principle of the Richter replacement.

dip--dependency Inversion principle.

isp--interface Isolation principle.

Package-oriented include: The emphasis is on the cohesion of the package design requirements->rep--reuse publishing equivalence principle.

ccp--the principle of common closure.

crp--Common reuse principle.

For the inter-package coupling requirement, the->adp--principle of non-cyclic dependence is required.

spp--the principle of stable dependence.

sap--Stable abstract principle.

Six major design principles:

Single duty principle srp--Responsibility Principle: A class should have only one reason for change.

A class should have only one cause for it to change, and do not encapsulate responsibilities that vary in reason and should be separated.

Key points: What is the responsibility of the class and how to divide the responsibilities of the class.

For interfaces, the design must be single, but for the implementation of the class requires more considerations, a single responsibility for

interface, class, and also apply to methods, a method to do as much as possible, for the single responsibility of the principle of recommendation is the interface must do

To a single duty, the class is designed to do as much as possible for only one cause to change.

Open closure principle Ocp--open Closed Principle: Software entities (classes, modules, functions, etc.) should be extensible but cannot be modified.

Software entities should be open to extensions and closed for modifications.

Dependency inversion principle dip--dependence inversion Principle: Abstractions should not be dependent on detail, and detail should be dependent on abstraction.

Rely on abstraction instead of relying on specifics because abstractions are relatively stable.

Interface Isolation principle Isp--interface segregation Principle: Customers should not be forced to rely on unused methods, the interface belongs to the customer and does not belong to

The class hierarchy in which it resides.

As far as possible the application of specialized interfaces, rather than a single total interface, the interface should be user-oriented to establish a dependency on the smallest interface.

Richter Replacement principle LSP Liskov substitation Principle: subtypes must be able to replace their base types.

Dimitri Rule LOD Law of Demeter: Also known as the least-known principle, refers to software entities should be as few as possible with other software entities interaction.

C # design pattern: Six 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.