• .NET面试之面向对象(一)


    面向对象的基本原则

    一。Encapsulate things in your design that are likely to change(封装变化)

      We isolate the parts that will change a lot into a sparate class or classes that we can depend on changing, and we increase our flexibility and ease of change. We also leave the stable part of our design alone, so that we just need to implement them once and test them once.(将变化的部分提取到单独的类,将稳定的部分保存在单独的类)

    二。Code to an Interface rather than an implementation(面向接口编程而不是面向具体实现)

         http://wenku.baidu.com/link?url=mPtltPKNn9MueYDA5TvFsmhUB3aGeKjoFbv8KC2Ji-AzrZmKlGeCGWnqkeIekE_FR0oeyLRZajlvELjdnAfuTvNPCJXVeLO2FdWodcvVrZ7 

    三。The open-closed principle(开闭原则)

      Classes should be open for extention and close for modification(对扩展开放,对修改关闭)

         Not only for classes, but also for methods.

    四。Don't repeat yourself principle(避免重复代码)

    五。The single responsibilty principle(单一职责原则)

      A class should have one, and only one reason to change.

    六。Liskov substitution principle(李氏置换原则)

      Subclasses must be substitutionable for their base class.(父类必须能被子类替代)

         getting the behavior of derived classes right and thus getting the inheritance right.

      Indications that you're violation LSP include:

      1. A subclass doesn't keep all the external observable behavior of its super class.

      2. A subclass modifies, rather than textends, the external observalble behavior of its super class.

      3. A subclass throws exceptions in an effort to hide certain behavior defined in its super class.

      4. A subclass that overrides a virtual method defined in its super class using an empty implementation in order to hide certain behavior defined in its super class.

      5. Method overrideing in derived classes is the beggest cause of LSP violations.

    七。Dependency inversion principle(依赖倒置原则)

      1. High-level modules should not depend on low-level modules. Both should depend on abstraction.

      2. Abstractions should not depend on details. Details should depend on abstractions.

    八。The interface segregation principle(接口分离原则)

      Clients should not have to depend on interfaces they don't use. In particular, they shouldn't have to depend on methods they don't use.

      Instead of adding new methods that are only appropriate to one or a few implementation classes,you make a new interface.

    九。The principle of least knowledge(最少知道原则)Law of Demeter(迪米特法则)

      Talk only to your immediate friends.

      The principle of least knowledge is all about loose coupling. Classes should collaborate indirectly as few other classes as possible.

  • 相关阅读:
    【WPF】绘制柱状图、折线图、扇形图
    【WPF】获取容器宽高
    【SQL】SQL Server、MySQL、SQLite获取自增ID、自增ID清零
    【SQL Server操作】SQL Server重命名数据库及解决数据库无法分离的问题
    【数据迁移】MySQL数据库迁移到SQL Server
    【MySQL操作】MySQL导入导出数据库
    【MySQL操作】MySQL Workbench远程连接的一些操作
    【c#】遍历获得一个类的所有属性名
    vue 跨域 springCloud @CrossOrigin注解
    解决IDEA右侧maven不显示方法
  • 原文地址:https://www.cnblogs.com/sift/p/3571088.html
Copyright © 2020-2023  润新知