Home  >  Article  >  Backend Development  >  Self-study C#04 from scratch--Features and design principles

Self-study C#04 from scratch--Features and design principles

黄舟
黄舟Original
2017-02-04 10:37:541088browse

1. Three major features

Encapsulation: Hide internal implementation.
Inheritance: Reuse existing code.
Polymorphism: rewrite object behavior.

2. Design principles

  • ##Single Responsibility Principle(SRP)

A class has only one cause of it Reason for change.

  • Open-Close Principle (OCP):

Class modules should be extensible, but cannot be modified. (Open to extension development, closed to modifications)

  • Liskov Substitution Principle(LSP):

Subclasses can be anywhere Replace its base class.

  • Interface Segregation Principle (ISP):

Try to use interfaces with single functions instead of interfaces with complex and comprehensive functions .

  • Dependence Inversion Principle (DIP):

High-level modules should not depend on low-level modules, both should depend on abstraction . Abstractions should not depend on implementation details; implementation details should depend on abstractions.

  • Law of Demeter or Least Knowledge Principle(LOD orLKP):

Requires as much encapsulation as possible, as much as possible Independent, try to use low-level access modifiers.

  • Composition/Aggregation Reuse Principle (CARP):

If you only achieve the purpose of code reuse, try to use it Composition and aggregation, not inheritance.

The above is the content of Self-Study C#04 from 0-Features and Design Principles. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn