面向对象:全再利用原则(CRP)

    介绍一下RobertC.Martin提出的面向对象的设计原则 中的全再利用原则。参考文档(http://www.objectmentor.com/resources/articles/granularity.pdf )。

    全再利用原则(CRP):The Common Reuse Principle。是为了解决包设计的凝集问题的。

    ·包里面的类能够一起被再利用,如果重用了包中的一个类,那么就要重用包中的所有类。( The classes in a package are reused together. If you reuse one of the classes in a package, you reuse them all.)。

     · 不能够被一起再利用的类不要放在同一个包里面。 Classes that aren’t reused together should not be grouped together)。

 

     面向对象的所有这些原则在实践中完全遵守是几乎不可能的,主要是没有那么时间和金钱让我们去仔细琢磨。不过我们了解认识了这些原则后,在设计的时候尽量使自己的产品分离性更高,效率好。易读,易扩展,易维护。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
# CRP Open source C++ Implementation of Customizable Route Planning (CRP) by Delling et al. This project was part of a practical course at Karlsruhe Institute of Technology (KIT). Requirements ============ In order to build CRP you need to have the following software installed: - Boost C++ Library (http://www.boost.org), more specifically Boost Iostreams. - Scons (http://scons.org) - g++ >= 4.8 (https://gcc.gnu.org) Building CRP ============ If the Boost Library is not in your PATH, make sure to edit the *SConstruct* file in the root directory to point the build script to the correct location of Boost. There is a section *Libraries* in the *SConstruct* file where you can specify the paths. Once you have installed all the software packages listed above, you can build the CRP programs by typing ``` scons --target=CRP --optimize=Opt -jX ``` into your terminal where `X` is the number of cores you want to use for building the project. If you want to use a specific g++ compiler version you can add `--compiler=g++-Version`. We also support a debug and profiling build that you can call with `--optimize=Dbg` and `--optimize=Pro` respectively. This command will build three programs in the folder *deploy*: - *osmparser*: Used to parse an OpenStreetMap (OSM) bz2-compressed map file. Call it with `./deploy/osmparser path_to_osm.bz2 path_to_output.graph.bz2` - *precalculation*: Used to build an overlay graph based on a given partition. Call it with `./deploy/precalculation path_to_graph path_to_mlp output_directory`. Here, *path_to_mlp* is the path to a *MultiLevelPartition* file for the graph that you need to provide. For more details, take a look into our project documentation. - *customization*: Used to precompute the metric weights for the overlay graph. Call it with `./deploy/customization path_to_graph path_to_overlay_graph metric_output_directory metric_type`. We currently support the following metric types: *hop* (number of edges traversed), *time* and *dist*.
面向对象八大设计原则是一组指导面向对象软件设计的原则,也被称为SOLID原则。这些原则旨在提高软件的可维护性、可扩展性和可重用性。下面是对这八大设计原则的介绍: 1. 单一职责原则(Single Responsibility Principle,SRP):一个类应该只有一个引起它变化的原因。换句话说,一个类应该只有一个职责。 2. 开放封闭原则(Open-Closed Principle,OCP):软件实体(类、模块、函数等)应该对扩展开放,对修改关闭。这意味着在不修改现有代码的情况下,可以通过添加新的代码来扩展功能。 3. 里氏替换原则(Liskov Substitution Principle,LSP):子类型必须能够替换掉它们的父类型。也就是说,如果一个类是父类的子类,那么它可以在任何使用父类的地方替代父类而不会引发错误。 4. 接口隔离原则(Interface Segregation Principle,ISP):客户端不应该依赖它不需要的接口。一个类不应该强迫它的客户端依赖于它们不使用的方法。 5. 依赖倒置原则(Dependency Inversion Principle,DIP):高层模块不应该依赖于低层模块,它们都应该依赖于抽象。抽象不应该依赖于具体实现,具体实现应该依赖于抽象。 6. 迪米特法则(Law of Demeter,LoD):一个对象应该对其他对象有尽可能少的了解。一个类应该只与它的直接朋友进行通信,而不是与陌生的类进行通信。 7. 合成复用原则(Composite Reuse Principle,CRP):尽量使用对象组合而不是继承来达到复用的目的。通过将对象组合在一起,可以灵活地增加新的行为,而不需要修改现有的代码。 8. 优先使用组合而不是继承原则(Prefer Composition Over Inheritance):在设计时,应优先考虑使用对象组合来实现代码的复用和扩展性,而不是过度使用继承。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值