140 likes | 237 Views
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
E N D
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 • More 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” another • Suggests a subclass/superclass relationship • Now use extends or implements • Gives new class all functionality of original • Prevents 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 hard • Law of Cybernetic Entomology: There is always one more bug • Why would we want to make it harder? • I can only remember ~3 things at once • Want to limit complexity of my life • Do not worry about code beyond method I am writing
Interfaces • Provide total abstraction of implementation • Specifies number of public methods • Classes 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 hard • Think about ways to simplify process
Where We Are • All these ADTs are types of Collections • Serve similar purpose: hold data for processing • Collections usually have certain functions: • Method to add data to Collection • Method to remove data from Collection • Method to get datum from Collection • Method to switch datum from Collection • Classes differ in how to access data
Where We Are (2) Sequence Collections of elementsAccess ends only Collection of elements;Access by rank Collection of Positions;Access via next & prev Deque IndexList PositionList Queue Stack List
Where We Are (3) • Collections of Entrys • Methods are named like IndexList, but uses the keys instead of ranks 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 note • Covers from last midterm through this week