首页 技术 正文
技术 2022年11月14日
0 收藏 558 点赞 3,808 浏览 1427 个字
  • Data Abstraction

    Hiding implementation

  • Data/Object Anti-Symmetry

    Objects hide their data behind abstractions and expose function that operate on that data. Data structure expose their data and hava no meaningful functions.

    Procedural code(code using data structure) makes it easy to add new functions without changing the existing data structures. OO code, on the other hand, makes it easy to add new classes without changing existing functions.

    Procedural code makes it hard to add new data structures because all functions must change. OO code makes it hard to add new functions because all the classes must change.

  • The Law of Demeter

    A module should not know about the innards of the objects it manipulates.

    A method f of a class C should only call the methods of these:

    • C
    • An object created by f
    • An object passed as an argument to f
    • An object held in an instance variable of C

    推荐一篇博文:笛米特法则详解,通过一个简单的代码示例解释了上述概念。

    • Train Wrecks

      Bad code:

      final String outputDir = ctxt.getOptions().getScratchDir().getAbsolutePath();

      Or

      Options opts = ctxt.getOptions();
      File scratchDir = opts.getScratchDir();
      final String outputDir = scratchDir.getAbsolutePath();

      Only used for data structures

      final String outputDir = ctxt.options.scratchDir.absolutePath;

    • Hybrids

      Avoid hybrid structures that are half object and half data structure.

    • Hiding Structure

      Tell an object to do something, not ask it about its internals.

  • Data Transfer Objects (DTO)

    The quintessential form of a data structure is a class with public variables and no functions.

    • Active Record

      Special form of DTO. Hava navigational methods like save and find.

      Typically direct translations from database tables, or other data sources.

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,022
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,359
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,142
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,773
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,851