Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Design Patterns
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Introduction== {{Overly detailed|section|date=October 2020}} Chapter 1 is a discussion of [[object-oriented]] design techniques, based on the authors' experience, which they believe would lead to good object-oriented software design, including: * "Program to an interface, not an implementation." (Gang of Four 1995:18) * [[Composition over inheritance]]: "Favor '[[object composition]]' over '[[Inheritance (object-oriented programming)|class inheritance]]'." (Gang of Four 1995:20) The authors claim the following as advantages of [[Interface (computer science)|interfaces]] over implementation: * clients remain unaware of the specific types of objects they use, as long as the object adheres to the interface * clients remain unaware of the classes that implement these objects; clients only know about the abstract class(es) defining the interface Use of an interface also leads to [[Dynamic dispatch|dynamic binding]] and [[Polymorphism (computer science)|polymorphism]], which are central features of object-oriented programming. The authors refer to [[Inheritance (object-oriented programming)|inheritance]] as ''[[White box (software engineering)|white-box]] reuse'', with white-box referring to visibility, because the internals of parent classes are often visible to [[Subclass (computer science)|subclasses]]. In contrast, the authors refer to [[object composition]] (in which objects with well-defined interfaces are used dynamically at runtime by objects obtaining references to other objects) as ''[[Black box|black-box]] reuse'' because no internal details of composed objects need be visible in the code using them. The authors discuss the tension between inheritance and encapsulation at length and state that in their experience, designers overuse inheritance (Gang of Four 1995:20). The danger is stated as follows: :"Because inheritance exposes a [[Subclass (computer science)|subclass]] to details of its parent's implementation, it's often said that 'inheritance breaks encapsulation'". (Gang of Four 1995:19) They warn that the implementation of a subclass can become so bound up with the implementation of its parent class that any change in the parent's implementation will force the subclass to change. Furthermore, they claim that a way to avoid this is to inherit only from abstract classes—but then, they point out that there is minimal code reuse. Using inheritance is recommended mainly when adding to the functionality of existing components, reusing most of the old code and adding relatively small amounts of new code. To the authors, 'delegation' is an extreme form of object composition that can always be used to replace inheritance. Delegation involves two objects: a 'sender' passes itself to a 'delegate' to let the delegate refer to the sender. Thus the link between two parts of a system are established only at runtime, not at compile-time. The [[Callback (computer science)|Callback]] article has more information about delegation. The authors also discuss so-called parameterized types, which are also known as [[Generic programming|generics]] ([[Ada (programming language)|Ada]], [[Eiffel (programming language)|Eiffel]], [[Generics in Java|Java]], [[C Sharp (programming language)|C#]], [[Visual Basic (.NET)]], and [[Delphi (software)|Delphi]]) or templates ([[C++]]). These allow any type to be defined without specifying all the other types it uses—the unspecified types are supplied as 'parameters' at the point of use. The authors admit that delegation and parameterization are very powerful but add a warning: :"Dynamic, highly parameterized software is harder to understand and build than more static software." (Gang of Four 1995:21) The authors further distinguish between '[[Object composition#Aggregation|Aggregation]]', where one object 'has' or 'is part of' another object (implying that an aggregate object and its owner have identical lifetimes) and acquaintance, where one object merely 'knows of' another object. Sometimes acquaintance is called 'association' or the 'using' relationship. Acquaintance objects may request operations of each other, but they are not responsible for each other. Acquaintance is a weaker relationship than aggregation and suggests much [[Loose coupling|looser coupling]] between objects, which can often be desirable for maximum maintainability in designs. The authors employ the term 'toolkit' where others might today use 'class library', as in C# or Java. In their parlance, toolkits are the object-oriented equivalent of subroutine libraries, whereas a '[[Software framework|framework]]' is a set of cooperating classes that make up a reusable design for a specific class of software. They state that applications are hard to design, toolkits are harder, and frameworks are the hardest to design.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Design Patterns
(section)
Add topic