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 Analysis and Design Using UML 翻译与学习 (十一)

Introducing Architectural Concepts and Diagrams 介绍架构概念和架构图 目标 完成这一模块(章),你可以: 1、区别架构和设计 2、描述阶层,层,...
  • CB44606
  • CB44606
  • 2016年11月27日 20:57
  • 563

Object-Oriented Analysis and Design Using UML 翻译与学习 (六)

Determining the Key Abstractions  确定重要的抽象 目标 完成这个模块,你可以 1、定义一组候选的重要的抽象 2、使用CRC分析来定义重要的抽象 进程阶...
  • CB44606
  • CB44606
  • 2016年10月22日 22:20
  • 265

OOAD(Object-Oriented Analysis and Design)介绍

OOAD方法论的定义:      1) 面向对象是一种系统建模技术;    2) 将系统描述为许多相互作用的有关系对象;    3) 系统中相互作用的对象被组织成类;    4) OO方法论由以...
  • yjptu
  • yjptu
  • 2013年10月10日 20:49
  • 831

Object Oriented Design -- Data and Algorithm Separation (1)

摘要:主要介绍软件设计过程中数据和算法分离的原则,以及用一个例子(可以适用于任何数据结构的通用二叉树算法)说明了具体的实现方式。这种设计思想其实与STL标准库中采用的方法很相似,不仅适用于二叉树,也适...

C++ Chapter 6. Inheritance and Object-Oriented Design

1. Public inheritance means "is-a." Everything that applies to base classes must also apply to deriv...
  • wyc1230
  • wyc1230
  • 2012年04月27日 13:19
  • 460

Object-Oriented Design Heuristics (zz)

Object-Oriented Design Heuristics //z 2012-4-18 10:17:10 AM IS2120@CSDN 第二章 类和对象:面向对象泛型的建材 经验原则...
  • is2120
  • is2120
  • 2012年04月18日 10:15
  • 501

Object-Oriented Analysis and Design Using UML 翻译与学习 (M-B)

构建软件解决方案 目标 完成这个模块(章节),你可以: 1、为解决模型定义一个Java技术包层级树 2、识别满足精心设计的领域模型的Java技术代码 进程图 为解决方案定义包结构...
  • CB44606
  • CB44606
  • 2017年04月09日 19:18
  • 121

Object-Oriented Analysis and Design Using UML 翻译与学习 (九)

Modeling Object State Using State Machine Diagrams 使用状态机图给对象状态建模 目标 完成这个模块(章节),你可以 1、给对象状态建模 2、U...
  • CB44606
  • CB44606
  • 2016年11月06日 16:18
  • 701

Object-Oriented Analysis and Design Using UML 翻译与学习 (十五)

回顾架构 目标 完成这个模块(章节),你可以: 1、定义一个框架 2、描述使用框架的优势和劣势 3、定义多种常用的框架 4、你创建你业务领域框架的概念 框架的描述 一个软件框架是一个可重用...
  • CB44606
  • CB44606
  • 2017年03月23日 22:27
  • 107

[转]Object Oriented Design Principles

Who is Audience? This article is intended for those who have at least a basic idea of Object orient...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Object Oriented Design Pricinple
举报原因:
原因补充:

(最多只允许输入30个字)