oop design 分为以下几个方面:

- encapsulation and modularity(封装和模块化)

- API/Client interface design(API 接口给调用类者)

- Inheritance hierarchy and interfaces(继承和继承的层次关系)

这里先介绍一个modularity模块化:

一个大的系统是很复杂的, 可能包含了很多复杂的部分, 如果编码中的一个部分可以独立出来而被其他部分所使用, 例如之前的cs106中的画火车的例子, 程序经过软件设计工程分解成小任务后, 不是直接开始编码, 而是看看有哪些部分可以独立出来, 这个独立出来的部分可以被很多子任务所使用(例如画车厢), 火车的车头, 车身和车尾都能利用上, 这个就是模块化 modularity – keep components as separate and independent from each other as possible. 同时, 将哪些部分独立编码进行模块化是需要很多经验的.

Standard Model OOP class Design(标准类设计)

  • Easy for the Client, 做到用户不用读文档, 就能很好的使用你提供的API.
  • Data private
  • one or more constructors(最好多个构造方法)
  • public getters, 给用户提供一些获得部分data的get方法.
  • public setters, 这个可以增加逻辑判断, 看用户修改的部分数据是否合理.
  • Methods as Transactions(参考了数据库中的transactions, 也就是说一个方法执行前是一个状态, 执行后是一个状态, 如果执行过程中出现问题, 那么要退回到执行前的状态并返回一个message)
  • Pirvate utility, You may decompose out a method for your own use within your class – declare it private unless there’s a good reason to expose it for client use.

继承

oop中经常出现的错误就是到处都是继承.

In java, no matter what code is being executed, the receiver object never forgets its class.

Student s; 这个声明的含义是什么 ?

s points to an object that responds to all the messages that Sutdents respond to

s points to a Student, or a subclass of Student

继承的语法与特点

subclass problems:

1. construct the part of the object that is inherited, using the superclass

在构造函数的第一行, 执行 super(arguments)

2. construct the part of the object due to the class itself.

在构造函数的第一行, 调用自己的另外一个构造函数

覆盖 即 重写

To override a method, a subclass just defines a method with exactly the same prototype – same name and arguments. With Java 5, you can provide an @Override annotation just before the method, and the compiler will check for you that it matches some superclass method.

断言方法

一般使用 is 或 has 开头的返回 boolean 的方法

IS-a : 子类是一个父类, has-a: 一个类中有另一个类作为此类的一部分

instance of : 一个 object 判断是否是一个类的实例, 例如: Student s = new Student(); s instanceof Student

Object class 提供哪些方法:

  • toString()
  • equals(Object other)
  • int hashCOde() allows an object to be a key in a HashMap, HashCode should be fast to compute. if a class does not implements hashCode() then it cannot be a key in a Hashmap

cs108 04 oop design的更多相关文章

  1. scala 学习笔记(04) OOP(上)主从构造器/私有属性/伴生对象(单例静态类)/apply方法/嵌套类

    一.主从构造器 java中构造函数没有主.从之分,只有构造器重载,但在scala中,每个类都有一个主构造器,在定义class时,如果啥也没写,默认有一个xxx()的主构造器 class Person ...

  2. C#语言-04.OOP基础

    a. OOP:面对对象思想 i. 类:是一种功能强大的数据类型,而且是面向对象的基础 . 语法:访问修饰符 class 类名{ //类的主体 } . 成员变量:不以“函数”形式体现 a. 常量:代表与 ...

  3. LN : Eden Polymorphic And OOP Design Pattern Abstract Factory

    Appreciation to our TA, +7, who designed this task. Client.cpp #include <iostream> #include &l ...

  4. 【翻译】设计模式学习系列1---【Design Patterns Simplified: Part 1【设计模式简述:第一部分】】

    原文链接:http://www.c-sharpcorner.com/UploadFile/19b1bd/design-patterns-simplified-part1/ Design Pattern ...

  5. 谷歌Web中国开发手册:1目的&amp;夹

    原版的:https://developers.google.com/web/fundamentals/getting-started/your-first-multi-screen-site/ 该网站 ...

  6. New需谨慎

    New is Glue When you’re working in a strongly typed language like C# or Visual Basic, instantiating ...

  7. (转)Awesome Courses

    Awesome Courses  Introduction There is a lot of hidden treasure lying within university pages scatte ...

  8. Creating a new dynamic form project, business modeling.

    The domain logic is like there are a bunch of objects, as well as a lot of configurations, according ...

  9. S03_CH05_AXI_DMA_HDMI图像输出

    S03_CH05_AXI_DMA_HDMI图像输出 5.1概述 本课程是在前面课程基础上添加HDMI IP 实现HDMI视频图像的输出.本课程出了多了HDMI输出接口,其他内容和<S03_CH0 ...

随机推荐

  1. PO_本地一揽子采购协议(流程)

    2014-06-04 Created By BaoXinjian

  2. Accelerated C++学习笔记7—&lt;使用库算法&gt;

    第6章  使用库算法 本章中主要教我们怎样使用几个库算法来解决与处理字符串和学生成绩相关的问题. 1.分析字符串 使用一个循环来连接两幅字符图案 <span style="font-f ...

  3. jenkins job构建后汇总结果到同一个文本文档中去

    jenkins 构建后,执行下shell脚本,把结果汇总到同一个文件中,这样多个job构建后的结果可以在一个文件中展示 result_all_dir="/app/jenkins_result ...

  4. django的hello world 项目

    一.新建一个django项目bester: django-admin startproject bester 二.在bester项目中建一个叫polls的应用程序: cd bester/ python ...

  5. Windows中将javac和java两个命令集成到UltraEdit工具栏

    1. 目的 将javac和java两个命令集成到UltraEdit工具栏,以方便在UltraEdit中编辑简单的java文件后,能够直接进行编译,运行. 2. 环境 UrtalEdit版本18.20: ...

  6. [svc]mousedos网络批量部署xp

    小时候对这个东西很好奇,不知道什么原理.一直觉得很好玩.现在研究了下,总结如下 软件的操作步骤很讲究,稍微不慎,则就需要重新来过 知识点: 1,掌握诺顿ghost分区为gh文件 2,学会清理至一个干净 ...

  7. winphone开发环境配置

    环境:操作系统win7 要进行winphone开发,必须进行一些环境的配置.下面是我的一些配置总结. 1.操作系统 winphone开发仅仅能在win8下开发.所以首先得安装win8.能够使用nt6 ...

  8. sparkSQL1.1入门之四:深入了解sparkSQL执行计划

    前面两章花了不少篇幅介绍了SparkSQL的执行过程,非常多读者还是认为当中的概念非常抽象.比方Unresolved LogicPlan.LogicPlan.PhysicalPlan是长得什么样子,没 ...

  9. DDOS与DDOS追踪的介绍

    我很早前研究anti-DDOS,其中就有追踪一块,可以在这里介绍一些,但是实际上只有很少技术被投入使用了,大多数都还是依然是实验室的东西,已经投入实用的我单独提出来. 追踪技术有: ·链级测试 (Li ...

  10. angular学习笔记(七)-迭代2

    视图的迭代和它的ng-repeat属性绑定的数据是实时绑定的,一旦数据发生了改变,视图也会立即更新迭代. 还是刚才的那个例子,给它添加一个添加数据按钮和一个删除数据按钮. <!DOCTYPE h ...