Object Oriented Design Pricinple

转载 2012年03月30日 17:27:21

What is object oriented design? What is it all about? What are it's benefits? What are it's costs? It may seem silly to ask these questions in a day and age when virtually every software developer is using an object oriented language of some kind. Yet the question is important because, it seems to me, that most of us use those languages without knowing why, and without knowing how to get the the most benefit out of them.

Of all the revolutions that have occurred in our industry, two have been so successful that they have permeated our mentality to the extent that we take them for granted. Structured Programming and Object Oriented Programming. All of our mainstream modern languages are strongly influenced by these two disciplines. Indeed, it has become difficult to write a program that does not have the external appearance of both structured programming and object oriented programming. Our mainstream languages do not have goto, and therefore appear to obey the most famous proscription of structured programming. Most of our mainstream languages are class based and do not support functions or variables that are not within a class, therefore they appear to obey the most obvious trappings of object oriented programming.

Programs written in these languages may look structured and object oriented, but looks can be decieving. All too often today's programmers are unaware of the principles that are the foundation of the disciplines that their languages were derived around. In another blog I'll discuss the principles of structured programming. In this blog I want to talk about the principles of object oriented programming.

In March of 1995, in comp.object, I wrote an article that was the first glimmer of a set of principles for OOD that I have written about many times since. You'll see them documented in my PPP book, and in many articles on the objectmentor website, including a well known summary.

These principles expose the dependency management aspects of OOD as opposed to the conceptualization and modeling aspects. This is not to say that OO is a poor tool for conceptualization of the problem space, or that it is not a good venue for creating models. Certainly many people get value out of these aspects of OO. The principles, however, focus very tightly on dependency management.

Dependency Management is an issue that most of us have faced. Whenever we bring up on our screens a nasty batch of tangled legacy code, we are experiencing the results of poor dependency management. Poor dependency managment leads to code that is hard to change, fragile, and non-reusable. Indeed, I talk about several different design smells in the PPP book, all relating to dependency management. On the other hand, when dependencies are well managed, the code remains flexible, robust, and reusable. So dependency management, and therefore these principles, are at the foudation of the -ilities that software developers desire.

The first five principles are principles of class design. They are:
SRP The Single Responsibility Principle A class should have one, and only one, reason to change.
OCP The Open Closed Principle You should be able to extend a classes behavior, without modifying it.
LSP The Liskov Substitution Principle Derived classes must be substitutable for their base classes.
DIP The Dependency Inversion Principle Depend on abstractions, not on concretions.
ISP The Interface Segregation Principle Make fine grained interfaces that are client specific.

The next six principles are about packages. In this context a package is a binary deliverable like a .jar file, or a dll as opposed to a namespace like a java package or a C++ namespace.

The first three package principles are about package cohesion, they tell us what to put inside packages:

REP The Release Reuse Equivalency Principle The granule of reuse is the granule of release.
CCP The Common Closure Principle Classes that change together are packaged together.
CRP The Common Reuse Principle Classes that are used together are packaged together.

The last three principles are about the couplings between packages, and talk about metrics that evaluate the package structure of a system.

ADP The Acyclic Dependencies Principle The dependency graph of packages must have no cycles.
SDP The Stable Dependencies Principle Depend in the direction of stability.
SAP The Stable Abstractions Principle Abstractness increases with stability.

面向对象数据库(Object Oriented Databases)

前面说几句费话。现在正在从事面向对象数据库在国内的推广工作,如果有兴趣可以与我联系。如果有任何问题可以私信我,也可以到我们网站上 面向对象数据库交流社区 来向我提问,我一定以最快的速度解答。 ...
  • grlsir
  • grlsir
  • 2014年09月30日 09:28
  • 2176

面向对象的程序设计(Object Oriented Programming)之一-----封装

一、面向对象的程序设计(Object Oriented Programming)之一-------封装:                     封装:把数据及对数据的操作方法放在一起,作为一个相互依...
  • u012131944
  • u012131944
  • 2013年10月05日 13:56
  • 493

面向对象(Object Oriented,OO) 的个人理解

1.子类方法对父类方法的 隐藏 与 重写     1.当子类的方法要 隐藏 父类的方法时可以在子类的方法前面添加 new 关键字     2.当子类的方法要 重写 父类的方法时可以在子类的方法前面添加...
  • pc1268
  • pc1268
  • 2013年10月09日 17:54
  • 295

面向对象的英文全称叫做Object Oriented

面向对象的英文全称叫做Object Oriented,简称OO。OO其实包括OOA(Object Oriented Analysis,面向对象分析)、OOD(Object Oriented Desig...
  • wsnbjj
  • wsnbjj
  • 2014年11月24日 13:03
  • 1214

Day6 面向对象(object oriented)思想

Day6 面向对象(object oriented)思想 *类与对象的概念: 类:是一组相关的属性和行为的集合 对象:该类事物的具体体现 学生是一个类,其中某个学生就是对象 ...
  • qq_39045534
  • qq_39045534
  • 2018年01月08日 19:48
  • 13

【JAVA核心技术卷一】Object Oriented面向对象

Object Oriented 面向对象面向对象 类 class 封装 encapsulation 继承 inheritance 面向对象的主要特性: 对象的标识(identity) ...
  • Houskii_Nian
  • Houskii_Nian
  • 2015年10月26日 17:51
  • 267

Ant-design 快速上手

1、在开始之前,先下载 Node.js v4.x 或以上。 2、安装后在win+r输入npm install antd-init -g 安装antd 3、使用命令行进行初始化。 $ mkdir an...
  • sinat_38270658
  • sinat_38270658
  • 2017年04月11日 14:28
  • 3168

【设计模式】Object Oriented面向对象思想剖析

OO思维(Object Oriented以对象为方向) 这里以"老张开车去东北"为例子。 创建一个ThinkInOO的工程: 先来看看小明的非面向对象思维的工程: package cn.e...
  • u013517797
  • u013517797
  • 2015年02月14日 12:12
  • 888

OC面向对象思想Object Oriented:类与对象

OC和java一样是面向对象的。 1.概念 OC是面向对象的,C是面向过程的。面向对象和面向过程只是解决问题的两种不同思想 面向对象和面向过程的区别 以用电脑听歌为例子 面向过程 打开电脑  播放电...
  • swon13
  • swon13
  • 2014年11月27日 01:28
  • 303


Intel长期与社区合作,以增强操作系统和软件的安全防护。但随着防护技术的增强,攻击者也相应地提高技术手段,JOP(Jump Oriented Programming)和ROP(Return Orie...
  • u012033027
  • u012033027
  • 2017年02月19日 21:57
  • 640
您举报文章:Object Oriented Design Pricinple