每一个object都含有state和method,因此定义一个object的时候一定要说明他的含有什么data member,还有什么method。
多用design pattern,少用inheritance;using interfaces
1. 设计一个文本编辑器
a)composite pattern来分别管理只读文本和可读写文本
b)singleton 一个文本管理manage
c) observer 可以告诉其他文本一些global状态的改变,比如format
2. Zoo
An interface for Animal,It has several abstract methods: sell, buy, sleep, eat
use composite pattern to implement different species animal, like bird, cat. These species are also abstract class. And the implementation of specific animal, like cat, tiger, puma.
each abstract class has a state: habit, which shows the common habit of a particular species. two methods: sethabit / gethabit.
each concrete class has more information: living area and so on. override method: sell buy, sleep, eat.