Slot 2 Review
Slot 2 Review
CONTENT
2
ABSTRACTION
• Abstraction is one of the main ways that we deal with complexity. It is the idea of
simplifying a concept in the problem domain.
• Abstraction breaks a concept down into a simplified description that emphasizes
the essentials needed for the concept, within some context.
DeliveryDriver
You were asked to create a DeliveryDriver class.
deliveryArea: DeliveryArea
You thought about the problem, and reduced it to
eyeColor: Color
its most essential aspects… things like takeOrder, height: int
DeliveryArea, etc. Irrelevant things in the context
(e.g., driver's height or eye colour) are ignored. takeOrder()
3
ABSTRACTION
4
abstract CLASS
• An abstract class can still have a constructor, which will be called by its subclasses,
during their construction.
5
abstract CLASS
• The purpose of an abstract class is to define the behavior its subclasses are
required to have, so it always participates in inheritance.
6
abstract METHOD
7
ENCAPSULATION
public public means any other class in any package can access this class.
protected allows classes in the same package, and any subclasses
protected
in other packages, to have access to the member.
When the modifier is omitted, this has special meaning, called
package access, meaning the member is accessible only to
classes in the same package
private private means that no other class can access this member
8
INHERITANCE
Animal
Vertebrates
Warm-blooded Cold-blooded
Dog Goldfish
Cat Salmon
9
INHERITANCE
Animal
type: String
• Dog inherits from Animal. size: String
• Dog "is-a" type of Animal. weight: double
move(String speed)
• When a Dog object is created, it will inherit makeNoise()
Animal's attributes (type, size and weight) &
Animal's methods.
• Dog class’ specific fields and behavior can
Dog
also be specialised
earShape: String
• Keywords: extends, super() tailShape: String
• Method overriding bark()
run()
walk()
wagTail() 10
POLYMORPHISM
watchMovie()
• Method’s behavior that occurs, while the
program is executing, depends on the
runtime type of the object.
12
COLLECTIONS
13
COLLECTIONS: a Big Picture
14
COLLECTIONS: some common classes
15