1 / 14

CSC 212 – Data Structures

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

paki-parker
Download Presentation

CSC 212 – Data Structures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC 212 –Data Structures Lecture 30: Midterm Review

  2. 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”

  3. 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”

  4. 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

  5. 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!

  6. 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

  7. 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

  8. Working With Linked Lists (1)

  9. Working With Linked Lists (2)

  10. 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

  11. 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

  12. Where We Are (3) • Collections of Entrys • Methods are named like IndexList, but uses the keys instead of ranks Map Dictionary

  13. Your Turn • Get back into groups and do activity

  14. 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

More Related