Difference between revisions of "OOP Design Principles"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with "Be aware of the following object-oriented design principles: ==encapsulate what varies== ==favour composition over inheritance== ==program to interfaces, not implementation==")
 
Line 1: Line 1:
Be aware of the following object-oriented design principles:
+
OOP has added many features and elements to basic Procedure-oriented programming. Writing good code, or designing OOP programs well, requires more care and planning. To help with writing good programs, OOP comes with some Design Principles to help us design and plan our programs.
==encapsulate what varies==
+
 
==favour composition over inheritance==
+
== encapsulate what varies ==
==program to interfaces, not implementation==
+
 
 +
"A test for good software design is how well it can deal with future change.  As the cliche truthfully claims, the only constant is change.  Inevitably any piece of software that is in use will be asked to change. Business needs will evolve or the problem space will be better understood, etc. Whatever the reason, the software will need to change.  A good design will allow for that change without too much work.  A bad design will be very hard to modify. "
 +
...
 +
"When designing software, look for the portions most likely to change and prepare them for future expansion by shielding the rest of the program from that change.  Hide the potential variation behind an interface.  Then, when the implementation changes, software written to the interface doesn’t need to change.  This is called encapsulating variation."
 +
https://blogs.msdn.microsoft.com/steverowe/2007/12/26/encapsulate-what-varies/
 +
 
 +
== favour composition over inheritance ==
 +
 
 +
[[w:Composition_over_inheritance]]
 +
 
 +
== program to interfaces, not implementation ==
 +
 
 +
Worked example w.r.t. "finding commonality in otherwise unrelated items"
 +
 
 +
http://stackoverflow.com/a/384067

Revision as of 06:05, 26 May 2017

OOP has added many features and elements to basic Procedure-oriented programming. Writing good code, or designing OOP programs well, requires more care and planning. To help with writing good programs, OOP comes with some Design Principles to help us design and plan our programs.

encapsulate what varies

"A test for good software design is how well it can deal with future change. As the cliche truthfully claims, the only constant is change. Inevitably any piece of software that is in use will be asked to change. Business needs will evolve or the problem space will be better understood, etc. Whatever the reason, the software will need to change. A good design will allow for that change without too much work. A bad design will be very hard to modify. " ... "When designing software, look for the portions most likely to change and prepare them for future expansion by shielding the rest of the program from that change. Hide the potential variation behind an interface. Then, when the implementation changes, software written to the interface doesn’t need to change. This is called encapsulating variation." https://blogs.msdn.microsoft.com/steverowe/2007/12/26/encapsulate-what-varies/

favour composition over inheritance

w:Composition_over_inheritance

program to interfaces, not implementation

Worked example w.r.t. "finding commonality in otherwise unrelated items"

http://stackoverflow.com/a/384067