Pay for Hesitation: OO Design Principles

Pages

2010年4月19日 星期一

OO Design Principles


Identify the aspects of your application that vary and separate them from what stays the same.
Favor composition over inheritance.
Strive for loosely coupled designs between objects that interact.
Open-Closed Principle: Class should be open for extension, but closed for modification.
Dependency Inversion Principle: Depend upon abstractions. Do not depend upon concrete classes.
No variables should hold a reference to a concrete class.
No class should derive from a concrete class.
No method should override an implemented method of any of its base class.
Principle of Least Knowledge - talk only to your immediate friends. (It means when you are designing a system, for any object, be care of the number of classes it interacts with and also how it comes to interact with those classes.)

The Hollywood Principle: Don't call us, we'll call you.

A class should have only one reason to change.

Null Object: A null object is useful when you don't have a meaningful object to return, and yet you want to remove the responsibility for handling null from the client. (p.214, NoComand and p.372 Null Iterator)

沒有留言: