- 1、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
重大18_Principles of object-oriented design
Object-Oriented Programming C++ 18 Agile software development Object-Oriented Programming C++ 01 Course Overview Object-Oriented Programming C++ College of Computer Science, CQU 18 Principles of object-oriented design Liu Ji liujiboy@163.com liujiboy@ * Outline SRP:the single-responsibility principle OCP:the open-closed principle LSP:the liskov substitution principle DIP:the dependency-inversion principle ISP:the interface segregation principle * References SRP In?object-oriented programming, the?single responsibility principle?states that every object should have a single responsibility, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility. * SRP example The Rectangle class has two responsibilities. The first responsibility is to provide a mathematical model of the geometry of a rectangle (area method). The second responsibility is to render the rectangle on a graphical user interface(draw method). This design violates the SRP. * The violation of SRP causes several nasty problems. Firstly, we must include the GUI in the computational geometry application. If this were a C++ application, the GUI would have to be linked in, consuming link time, compile time, and memory footprint Secondly, if a change to the GraphicalApplication causes the Rectangle to change for some reason, that change may force us to rebuild, retest, and redeploy the ComputationalGeometryApplication. If we forget to do this, that application may break in unpredictable ways. * A better design is to separate the two responsibilities into two completely different classes. This design moves the computational portions of Rectangle into the GeometricRectangle class. Now changes made to the way rectangles are rendered cannot affect the ComputationalGeometryApplication. * OCP OCP?states software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification;?that is, such an ent
文档评论(0)