当前位置:网站首页>23 design models
23 design models
2022-07-03 06:11:00 【Master core technology】
One 、 Design model overview
Definition
Design patterns (Design Pattern) It's a summary of code development experience of predecessors , It's a series of solutions to specific problems . It's not a grammatical rule , It's a set to improve code reusability 、 Maintainability 、 Readability 、 Solutions for robustness and security .
The essence of design pattern is the practical application of object-oriented design principle , It's encapsulation of classes 、 Inheritance and polymorphism as well as the full understanding of class association and composition .
23 Design models :GoF23
1) Create pattern :
The singleton pattern 、 Factory mode 、 Abstract factory pattern 、 Builder pattern 、 Archetypal model .
2) Structural mode :
Adapter pattern , Bridging mode , Decoration mode , Portfolio model , Appearance mode , The flyweight pattern , The proxy pattern
3) Behavioral patterns :
Template method pattern , Command mode , Iterator pattern , Observer mode , Intermediary model , Memo mode , Interpreter mode , The state pattern , The strategy pattern , Responsibility chain pattern , Visitor mode .
OOP The seven principles
* Opening and closing principle : Open to expansion , Turn off for changes
Richter's principle of substitution : Inheritance must ensure that the properties owned by the superclass are still valid in the subclass
The principle of Dependence Inversion : Interface oriented programming , Don't program for implementation .
Principle of single responsibility : Control the granularity of the class 、 Decouple objects 、 Improve its cohesion .
Interface isolation principle : To create the specialized interfaces they need for each class
Dimitar's law : Just talk to your direct friends , Not with “ A stranger ” speak .
Synthetic multiplexing principle : Try to use association relations such as composition or aggregation to achieve , Second, consider using inheritance relationship to achieve .
Two 、UML
UML Concept
Unified modeling language (Unified Modeling Language,UML) It's a visual modeling language for software design . It is characterized by simplicity 、 Unified 、 Graphical 、 It can express dynamic and static information in software design .UML From different perspectives of the target system , Define the use case diagram 、 Class diagram 、 Object graph 、 State diagram 、 Activity diagrams 、 Sequence diagram 、 Collaboration map 、 Component diagram . Deployment diagram, etc 9 Seed map .
Class diagram Overview
Class diagram (Class diagram) It shows the static structure of the model , Especially the classes that exist in the model 、 The internal structure of classes and their relationships with other classes . Class diagrams don't show transient information . Class diagram is the main part of object-oriented modeling .
The function of class diagram
In software engineering , A class diagram is a static structure diagram , Describes the collection of classes of the system , The properties of a class and the relationships between classes , It can simplify people's understanding of the system ; Class diagram is an important product of system analysis and design , It's an important model for system coding and testing .
Class diagram representation
+ Express public
- Express private
# Express protected
The complete representation of attributes is : visibility name ︰ type [ = The default value ]
The complete representation of a method is : visibility name ( parameter list ) [ : Return type ]
The representation of the relationship between classes
1) Connections
Association is a kind of reference relationship between objects , Used to represent the relationship between one class of objects and another class of objects . Association is the most commonly used relationship between classes , It can be divided into general relationship 、 Aggregation and composition . Association can be divided into one-way Association , Two way connection , Self correlation .
1, One way Association
stay UML One way Association in the class diagram is represented by a solid line with an arrow . The picture above shows that every customer has an address , It's by making customer Class holds a type of Address Member variable class implementation of .
2, Two way connection
It's easy to see from the picture above , The so-called two-way association is that both sides hold each other's type of member variables . stay UML In class diagram , Bidirectional association is represented by a straight line without an arrow . The picture above shows Customer Maintain one in the class List, It means that a customer can buy more than one product ; stay Product Maintain one in the class customer The member variable of type indicates which customer purchased the product .
3, Self correlation
Self correlation in UML The class diagram is represented by a line with an arrow pointing to itself . The picture above means Node Class contains the type Node Member variables of , That is to say "“ Self contained ”.
2) Aggregate relationship
Aggregation is a kind of association , It's a strong correlation , It's the relationship between the whole and the part . Aggregation relationships are also implemented through member objects , The member object is a part of the whole object , But member objects can exist independently of the whole object . for example , The relationship between school and teachers , The school contains teachers , But if the school is closed , Teachers still exist . stay UML In class diagram , The aggregation relationship can be represented by a solid line with a hollow diamond , Rhombus pointing to the whole .
3) synthetic relation
Composition represents the relationship between the whole and the parts of a class , But it's a stronger aggregation . In a combinatorial relationship , The whole object can control the life cycle of some objects . Once the whole object doesn't exist , Some objects will not exist , Some objects cannot exist apart from the whole . for example , The relationship between head and mouth , No head , The mouth doesn't exist . stay UML In class diagram , A combination is represented by a solid line with a solid diamond , Rhombus pointing to the whole .
4) Dependency relationship
Dependency is a kind of usage relationship , It's the weakest way of associating objects , It's a temporary connection . In the code , Methods of a class pass through local variables 、 Method or a call to a static method to access another class ( Dependent class ) Some of the ways to accomplish some of the responsibilities . stay UML In class diagram , Dependencies are represented by dotted lines with arrows , The arrow points from the use class to the dependent class . The diagram below shows the relationship between driver and car , The driver drives the car :
5) Inheritance relationships
Inheritance is the most coupling relationship between objects , To express a general or special relationship , Is the relationship between the parent class and the child class , It's an inheritance relationship . stay UML In class diagram , The generalization relationship is represented by a solid line with a hollow triangle arrow , The arrow points from the child class to the parent class . When the code is implemented , Use object-oriented inheritance mechanism to achieve generalization relationship . for example ,Student Classes and Teacher Classes are Person Subclasses of classes , The class diagram is shown in the following figure ;
6) Realization relationship
Implementation relationship is the relationship between interface and implementation class . In this relationship , Class implements the interface , The operations in the class implement all the abstract operations declared in the interface . stay UML In class diagram , The implementation relationship is represented by a dotted line with a white triangle arrow , The arrow points from the implementation class to the interface . for example , Cars and boats make transportation possible , The class diagram is as shown in figure 9 Shown .
边栏推荐
- In depth analysis of kubernetes controller runtime
- 智牛股--03
- PHP用ENV获取文件参数的时候拿到的是字符串
- 使用conda创建自己的深度学习环境
- Kubesphere - build Nacos cluster
- 表达式的动态解析和计算,Flee用起来真香
- What's the difference between using the Service Worker Cache API and regular browser cache?
- 理解 期望(均值/估计值)和方差
- 代码管理工具
- Multithreading and high concurrency (7) -- from reentrantlock to AQS source code (20000 words, one understanding AQS)
猜你喜欢
深度学习,从一维特性输入到多维特征输入引发的思考
项目总结--2(Jsoup的基本使用)
[Zhao Yuqiang] deploy kubernetes cluster with binary package
Oauth2.0 - explanation of simplified mode, password mode and client mode
最大似然估计,散度,交叉熵
. Net program configuration file operation (INI, CFG, config)
Synthetic keyword and NBAC mechanism
[teacher Zhao Yuqiang] calculate aggregation using MapReduce in mongodb
Skywalking8.7 source code analysis (II): Custom agent, service loading, witness component version identification, transform workflow
Zhiniu stock project -- 04
随机推荐
If function of MySQL
GPS坐标转百度地图坐标的方法
MySQL帶二進制的庫錶導出導入
The programmer shell with a monthly salary of more than 10000 becomes a grammar skill for secondary school. Do you often use it!!!
About the difference between count (1), count (*), and count (column name)
Oracle database synonym creation
ODL framework project construction trial -demo
Txt document download save as solution
BeanDefinitionRegistryPostProcessor
代码管理工具
Project summary --01 (addition, deletion, modification and query of interfaces; use of multithreading)
BeanDefinitionRegistryPostProcessor
Why should there be a firewall? This time xiaowai has something to say!!!
从小数据量 MySQL 迁移数据到 TiDB
Simple solution of small up main lottery in station B
Nacos service installation
[teacher Zhao Yuqiang] RDB persistence of redis
智牛股--03
Zhiniu stock project -- 05
Installation of CAD plug-ins and automatic loading of DLL and ARX