加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

OOD之思路乱发散

发布时间:2020-12-13 19:59:13 所属栏目:百科 来源:网络整理
导读:每一个object都含有state和method,因此定义一个object的时候一定要说明他的含有什么data member,还有什么method。 多用design pattern,少用inheritance; using interfaces 1. 设计一个文本编辑器 a)composite pattern来分别管理只读文本和可读写文本 b

每一个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 differentspecies 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. eachconcrete class has more information: living area and so on. override method: sell buy,eat.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读