当前位置:网站首页>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 .
边栏推荐
- 轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
- 项目总结--01(接口的增删改查;多线程的使用)
- 智牛股项目--04
- Detailed explanation of findloadedclass
- BeanDefinitionRegistryPostProcessor
- Kubesphere - build MySQL master-slave replication structure
- [teacher Zhao Yuqiang] Flink's dataset operator
- CAD插件的安裝和自動加載dll、arx
- Oauth2.0 - using JWT to replace token and JWT content enhancement
- Bio, NiO, AIO details
猜你喜欢
[Zhao Yuqiang] deploy kubernetes cluster with binary package
Bio, NiO, AIO details
Project summary --04
[video of Teacher Zhao Yuqiang's speech on wot] redis high performance cache and persistence
[teacher Zhao Yuqiang] redis's slow query log
Fluentd facile à utiliser avec le marché des plug - ins rainbond pour une collecte de journaux plus rapide
多线程与高并发(7)——从ReentrantLock到AQS源码(两万字大章,一篇理解AQS)
Pytorch builds the simplest version of neural network
理解 YOLOV1 第一篇 预测阶段
Kubesphere - Multi tenant management
随机推荐
Solve the problem that Anaconda environment cannot be accessed in PowerShell
Project summary --01 (addition, deletion, modification and query of interfaces; use of multithreading)
Fluentd facile à utiliser avec le marché des plug - ins rainbond pour une collecte de journaux plus rapide
[teacher Zhao Yuqiang] Alibaba cloud big data ACP certified Alibaba big data product system
[system design] proximity service
Skywalking8.7 source code analysis (II): Custom agent, service loading, witness component version identification, transform workflow
Understand the first prediction stage of yolov1
Oauth2.0 - using JWT to replace token and JWT content enhancement
Click cesium to obtain three-dimensional coordinates (longitude, latitude and elevation)
When PHP uses env to obtain file parameters, it gets strings
深入解析kubernetes controller-runtime
Alibaba cloud Alipay sandbox payment
从小数据量 MySQL 迁移数据到 TiDB
ThreadLocal的简单理解
【系统设计】邻近服务
88. Merge two ordered arrays
Beandefinitionregistrypostprocessor
[teacher Zhao Yuqiang] calculate aggregation using MapReduce in mongodb
Advanced technology management - do you know the whole picture of growth?
JS implements the problem of closing the current child window and refreshing the parent window