3 Adt&tdd
3 Adt&tdd
3 Adt&tdd
and Test-Driven
Development
Unit 3
CPRG304 – Object-Oriented
Programming III
1. Inheritance – “is a”
2. Polymorphism – “one name, many forms”
• Subtype or parametric
3. Encapsulation – “time capsule”
• Orthogonality (separation of concerns/responsibility)
4. Abstraction – “need-to-know basis”
Abstraction
• Suppressing details to emphasize on what is relevant at
the moment
• Represent data at a conceptual level without any details
Exceptions
Common Operations (Method Types)
• Constructors – creates the ADT and initializes state
• Accessors (Getters) – returns a value from the
collections or the whole collection, or some information
about the ADT
• next(), min(), size()
• Mutators (Setters) – modifies the collection in any way
• add(), replace(), clear()
• Transformers – similar to getters but changes the data
value or type being returned
• isEmpty(), calcVolume(), calcBaseArea()
CounterADT Exercise
• We need a class called Counter. An object of this class
will be used to count things, so it will record a count
that is a non-negative whole number. This class will
need to set the counters to a given integer, increase the
count by 1, and to decrease the count by 1. We will
need to be able to return the current count as an
integer and a string to be displayed on the screen. It is
important to be able to determine if the counter is zero
at any given point in time.
Step 1 - Understand
Counter
- counter: int
+ setCounter( num: int ) : void
+ incCounter() : void
+ decCounter() : void
+ getCounter() : int
+ toString() : String
+ isZero() : Boolean
• Documentation is CRITICAL!
• Just as you would read the Java API to understand how to use
a class and its methods, we need to be VERY precise in our
JavaDoc to let users know how to use and what to expect
from our ADT!