当前位置:网站首页>(construction notes) learn the specific technology of how to design reusable software entities from three levels: class, API and framework
(construction notes) learn the specific technology of how to design reusable software entities from three levels: class, API and framework
2022-07-03 12:03:00 【Special case】
From the class 、API、 The three levels of the framework learn how to design specific technologies of reusable software entities
Reuse level :
Code reuse
Including the reuse of object code and source code . The reuse level of the object code is the lowest , It has the longest history , At present, most of the running support systems of programming languages provide connections (Link)、 binding (Binding) And other functions to support this reuse . The reuse level of source code is slightly higher than that of object code , Programmers copy some code segments they want to reuse into their own programs , But this often leads to some errors that the old and new code do not match . If you want to realize the reuse of source programs on a large scale, you can only rely on the component library containing a large number of reusable components . Such as ” Object linking and embedding ”(OLE) technology , It supports the definition of components at the source program level and the construction of new systems , These components are still independent reusable components at the level of object code , It can be flexibly combined into different applications at runtime .
Reuse of design
The design result is more abstract than the source program , Therefore, its reuse is less affected by the implementation environment , Thus, there are more opportunities for reusable components to be reused , And fewer changes are required . There are three ways to reuse this , The first approach is to extract some reusable design components from the design results of existing systems , These components are applied to the design of the new system ; The second way is to re implement all the design documents of an existing system on a new software and hardware platform , That is to apply a design to multiple specific implementations ; The third approach is independent of any specific application , Develop some reusable design components in a planned way .Reuse of analysis
This is a higher level of reuse than the design result , Reusable analysis components are more abstract solutions to some things or problems in the problem domain , It is rarely affected by design technology and implementation conditions , So there is a greater chance of reusability . There are also three ways to reuse , That is to extract reusable components from the analysis results of existing systems for the analysis of new systems ; A complete analysis document is used as input to generate multiple designs for different software and hardware platforms and other implementation conditions ; Application independent , Develop some reusable analysis components .Reuse of test information
It mainly includes the reuse of test cases and test process information . The former is to use a software test case in a new software test , Or use it in a new round of testing when the software is modified . The latter is to record the test process information automatically through software tools during the test process , Including every operation of the tester 、 Input parameters 、 Test cases, operating environment and other information . This level of reuse , Inconvenience and analysis 、 Design 、 Program reuse level for accurate comparison , Because what is reused is not different levels of abstraction of the same thing , It's another message , But from the form of this information , Roughly at the level of program code .
Because the software production process is mainly a positive process , That is, the production process of most software is to make software products evolve from a higher level of abstraction to a lower level of abstraction , Therefore, higher-level reuse is easy to drive lower-level reuse , Therefore, the higher the level of reuse , The greater the return you can get , Therefore, the analysis results and design results are highly valued at present . Users can buy the manufacturer's analysis parts and design parts , Design or program by yourself , Master the tailoring of the system 、 expand 、 maintain 、 Evolution and other activities .
Reusable classes :
Delegation and combination
entrust (Delegation)
delegate / entrust : One object requests the function of another , Is a common form of reuse .
Delegation can be described as a low-level mechanism for sharing code and data between entities
Delegates depend on dynamic binding , Because it requires that a given method call can call different code segments at run time .
Comparison of delegation and inheritance :
Inherit : Extend the base class or override operation with a new operation .
entrust : Take the base class as the element of the new class , You can extend the functions of the new class with the functions implemented by the base class
Delegation can replace inheritance : If the subclass only needs to reuse a small number of methods in the parent class , Yes, No
To use inheritance , But through the delegation mechanism
The principle of combinatorial inheritance
Classes should realize polymorphic behavior and code reuse through their combination ( By including instances of other classes that implement the required functionality ), Instead of inheriting from the base class or parent class .
Combination principle :
Use interfaces to define the behavior of different aspects that the system must show to the outside world , for example , A bird can sing or fly , Then you can define two interfaces ,quackable and flyable.
Interface through extends Extension of implementation behavior ( Interface combination ). Then you can define an interface birdable At the same time, it inherits the above two interfaces , In this way, the new interface has all the functions of the above two interfaces .
class implements Composite interface , Thus avoiding the complex inheritance relationship . Next , We define “ birds ” Can be realized birdable, Make the function of the activity top-level interface ( In the process of constructing the instance , At the same time delegation Interface of top-level functions )
Reusable API And framework :
Why library and frame It is called system level reuse , Because they not only define 1 Reusable interfaces / class , Instead, all reusable interfaces in a complete system / Classes are implemented , And defines the interaction between these classes 、 Call relationship , Thus forming the whole system Of “ framework ”.
Write a API The following aspects need to be considered :
- API One thing should be done , And did a good job
- API It should be as small as possible , But not too small
- Implementation Should not affect API
- Documentation is heavy
- Consider performance consequences
- API Must coexist peacefully with the platform
- Class design : Minimize variability , follow LSP principle
- Method design : Don't let the customer do what any module can do , Timely error reporting
frame
The frame is divided into white box frame and black box frame .
White box frame :
Extend by subclassing and overriding methods ( Using inheritance );
Common design patterns : Template method ;
Subclasses have primary methods but control the framework .
Black box frame :
Extend by implementing the plug-in interface ( Use combination / delegate );
Common design patterns :Strategy, Observer ;
The plug-in loading mechanism loads the plug-ins and controls the framework .
边栏推荐
- 同事写了一个责任链模式,bug无数...
- After watching the video, AI model learned to play my world: cutting trees, making boxes, making stone picks, everything is good
- [official MySQL document] deadlock
- vulnhub之Ripper
- ArcGIS应用(二十一)Arcmap删除图层指定要素的方法
- Qt+vtk+occt reading iges/step model
- win10 上PHP artisan storage:link 出现 symlink (): Protocol error的解决办法
- Visual studio 2022 downloading and configuring opencv4.5.5
- rxjs Observable filter Operator 的实现原理介绍
- 《剑指offer 04》二维数组查找
猜你喜欢

vulnhub之cereal
![[MySQL special] read lock and write lock](/img/ac/e01c26882cc664ea2e5e731c5a8bab.png)
[MySQL special] read lock and write lock

Hongmeng fourth training

STL Tutorial 9 deep copy and shallow copy of container elements

During FTP login, the error "530 login incorrect.login failed" is reported

Talk about the state management mechanism in Flink framework

Duplicate numbers in the array of sword finger offer 03

836. 合并集合(DAY 63)并查集
![[learning notes] DP status and transfer](/img/5e/59c64d2fe08b89fba2d7e1e6de2761.png)
[learning notes] DP status and transfer

ArcGIS应用(二十一)Arcmap删除图层指定要素的方法
随机推荐
Oracle advanced (I) realize DMP by expdp impdp command
(构造笔记)ADT与OOP
MCDF实验1
Xiaopeng P7 hit the guardrail and the airbag did not pop up. The official responded that the impact strength did not meet the ejection requirements
Master and backup role election strategy in kept
Vulnhub's presidential
vulnhub之GeminiInc v2
Why can't my MySQL container start
vulnhub之Ripper
Qt OpenGL 旋转、平移、缩放
Vulnhub narak
Quantitative calculation research
PHP导出word方法(一phpword)
简单工厂和工厂方法模式
Hongmeng fourth training
Talk about the state management mechanism in Flink framework
2022年湖南工学院ACM集训第二次周测题解
Dynamically monitor disk i/o with ZABBIX
Ripper of vulnhub
Solutions to the failure of installing electron