csc 212 – data structures
DESCRIPTION
CSC 212 – Data Structures. Lecture 30: Midterm Review. Composing/Combining Classes. When class “ has ” or “ uses ” another class Define field(s) or local(s) of latter class Do not use extends nor use implements Gives new class all functionality of original - PowerPoint PPT PresentationTRANSCRIPT
CSC 212 –Data Structures
Lecture 30:
Midterm Review
Composing/Combining Classes
When class “has” or “uses” another classDefine field(s) or local(s) of latter class
Do not use extends nor use implementsGives new class all functionality of originalMore than having or using certain capabilities
“I have an arm” != “I am 5 fingers and a palm”
“I use a fork” != “I have 4 silver tines”
Composing/Combining Classes
When class “is” or “includes” anotherSuggests a subclass/superclass relationship
Now use extends or implementsGives new class all functionality of originalPrevents rewriting methods and automatically
exposes functionality “I am a bird” “I am an animal” “I am a CSC professor” “I am a geek”
Interfaces
Programming is already hardLaw of Cybernetic Entomology:
There is always one more bugWhy would we want to make it harder?
I can only remember ~3 things at onceWant to limit complexity of my lifeDo not worry about code beyond method I am
writing
Interfaces
Provide total abstraction of implementationSpecifies number of public methodsClasses must include implementation of every
method Allows you to use simplified model
Forcibly divorced from how it is implemented Similar to how you all use String
In my system, takes 1000+ lines of code Includes a HashMap!
When To Break an Interface
“Break” interface by getting actual class
ONLY DO THIS WHEN NECESSARY!Only break what you make!
Break interfaces only for objects the class creates
Better to use methods in interface
Writing & Debugging Classes
Try limiting the amount of code to write Use other methods whenever possible
Careful about replacing O(1) operation with O(n) method call
Remember, writing code is hardThink about ways to simplify process
Working With Linked Lists (1)
Working With Linked Lists (2)
Where We Are
All these ADTs are types of CollectionsServe similar purpose: hold data for
processing Collections usually have certain functions:
Method to add data to CollectionMethod to remove data from CollectionMethod to get datum from CollectionMethod to switch datum from Collection
Classes differ in how to access data
ListCollection
of elements;
Access by rank
Collection of Positions;Access via next & prev
Collections of elements
Access ends only
Where We Are (2)
Queue Stack
Deque IndexList PositionList
Sequence
• Collections of Entrys• Methods are named like IndexList, but uses the keys instead of ranks
Where We Are (3)
Map Dictionary
Your Turn
Get back into groups and do activity
Before Next Lecture…
Keep up with your reading!Cannot stress this enough
Continue Week #12 Assignment Read Programming Assignment #4 Prepare for Midterm #2 next Monday
Will also be open book, open noteCovers from last midterm through this week