Docsity

Design Principles for Object-Oriented Programming: Tamper-Proof, Well-Behaved Classes - Pr, Study notes of Software Engineering

Toggle sidebar
bg1
2/9/2009
Dr.PaulC.Grabow 1
Ch t
Ch
ap
t
er
3
2/9/2009 Dr.PaulC.Grabow
Outline
Noteverythingisofequalimportanceinthischapter
Thedateexampleisnotsuchagreatexample(skim)
Importantsections
3.1Tot al orderings(specialtopic)
3.2Operatoroverloading(specialtopi c)
3.4Importanceofencapsulation(everything)
3.5Analyzingthequalityofaninterface(everything)
3.6Programmingbycontract(everything)
3.6Unittestin g(wehavealreadydonethisinlab)
2/9/2009 Dr.PaulC.Grabow
SomeDesignPrinciples
Aninstanceofaclassshouldbe
“Tamper‐proof”
Wel l‐behaved
If illhldb
I
nstances
o
f
a
part
i
cu
l
ar
c
l
ass
s
h
ou
ldb
e
Ordered
Unique
Cohesive
Complete
Avoi dcouplin gbetweenclasses
2/9/2009 Dr.PaulC.Grabow
pf3

Partial preview of the text

Download Design Principles for Object-Oriented Programming: Tamper-Proof, Well-Behaved Classes - Pr and more Study notes Software Engineering in PDF only on Docsity!

ChCh aptert 3

2/9/2009 Dr. Paul C. Grabow

Outline

 Not everything is of equal importance in this chapter

 The date example is not such a great example (skim)

 Important sections

 3.1 Total orderings (special topic)  3.2 Operator overloading (special topic)  3.4 Importance of encapsulation (everything)  3.5 Analyzing the quality of an interface (everything)  3.6 Programming by contract (everything)  3.6 Unit testing (we have already done this in lab) 2/9/2009 Dr. Paul C. Grabow

Some Design Principles

 An instance of a class should be

 “Tamper‐proof”  Well‐behaved

 II nstances off a particulari l classl shouldh ld bbe

 Ordered  Unique  Cohesive  Complete

 Avoid coupling between classes

2/9/2009 Dr.^ Paul^ C.^ Grabow

Principles & Prog. Language

 To achieve good designs

 A programming language is necessary but not sufficient  Design principles should guide  DD esignsi  Use of a programming language (not vice versa)

 A “good” programming language cannot guarantee a

good design

 “Clever programming” often at odds with good design

2/9/2009 Dr. Paul C. Grabow

“Tamper‐proof” classes

 Distinguish between accessors and mutators (3.4.1)

 Use mutators sparingly (111)

 An accessor function

 Onlyl gets a valuel  Does not create a side effect

 User of the object should not

 Not have direct access to data within the object (109)  Be given a address of data from within the object (112)

 Use private and private final to protect object data (113)

2/9/2009 Dr. Paul C. Grabow

Well‐behaved

 An object should only

 Do what it is supposed to do and nothing more

 EE achh methodh d iin theh objectbj shouldh ld b hbehave

 The same way each time that it is called

 A method’s behavior should not be influenced by

 The values of its parameters 2/9/2009 Dr. Paul C. Grabow