csc 212 – data structures

14
CSC 212 – Data Structures Lecture 30: Midterm Review

Upload: paki-parker

Post on 30-Dec-2015

18 views

Category:

Documents


0 download

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 Presentation

TRANSCRIPT

Page 1: CSC 212 – Data Structures

CSC 212 –Data Structures

Lecture 30:

Midterm Review

Page 2: CSC 212 – Data Structures

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”

Page 3: CSC 212 – Data Structures

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”

Page 4: CSC 212 – Data Structures

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

Page 5: CSC 212 – Data Structures

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!

Page 6: CSC 212 – Data Structures

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

Page 7: CSC 212 – Data Structures

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

Page 8: CSC 212 – Data Structures

Working With Linked Lists (1)

Page 9: CSC 212 – Data Structures

Working With Linked Lists (2)

Page 10: CSC 212 – Data Structures

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

Page 11: CSC 212 – Data Structures

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

Page 12: CSC 212 – Data Structures

• Collections of Entrys• Methods are named like IndexList, but uses the keys instead of ranks

Where We Are (3)

Map Dictionary

Page 13: CSC 212 – Data Structures

Your Turn

Get back into groups and do activity

Page 14: CSC 212 – Data Structures

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