Docsity

Understanding OOP: Abstraction, Encapsulation, Inheritance, Modularity, Lab Reports of Advanced Calculus

Partial preview of the text

Download Understanding OOP: Abstraction, Encapsulation, Inheritance, Modularity and more Lab Reports Advanced Calculus in PDF only on Docsity!

CS

Topic:^

Intro. to Object Oriented Pgmg.^ Tuesday, Sept. 6, 2005

Announcements † Lab 1 due^ this Friday † Lab 2 is now available (online) (due Friday, Sept. 16)^ „^ Uses red-black trees^ „^ Still in C^ „^ Don’t procrastinate!!!Finish Lab 1 early, then get early start on Lab 2. † This week’s lab meetings will discuss Lab 2 assignment † ☺^ Today’s movie case study

: Movies of swarms, andrelationship to OOP

☺

Computational Models † A model is a

simplification

of reality † Main reason for developingmodels: „^ Understanding the systembeing developed † We build models of complexsystems because we cannotcomprehend such a system inits entirety

Principles of Modeling † The choice of the model has a significant impact onhow the problem is approached and how a solution isdevised † A model can be expressed at different levelsof precision † A good model is connected to reality † A single model is not sufficient to represent mostsystems; A set of

nearly^ independent models are required

Basic Principles of Object Orientation †^ Abstraction †^ Encapsulation †^ Modularity †^ Hierarchy †^ Inheritance

What is Abstraction?

Counter Queue

Items

†^ A model that includes most important aspectsof a given problem while ignoring lessimportant details^ An example of an item purchasing abstraction:

What is Modularity? †^ The breaking up of something complex intomanageable pieces or modules

Queue Canteen System

Order Placement Delivery Billing

What is Hierarchy? †^ Level of abstraction^ Increasingabstraction^

Art

Music^

Films^ Sculptures

R&B^ Rap

Sci-Fi^

… Action

DecreasingAbstraction

Example of Interface Inheritance † Suppose you want to define Search_Object_1 that: „^ Stores (key, value) pairs „^ Allows values to be looked up using keys „^ Supported operations for Search_Object_1:^ †^ insert:^

Adds a (key, value) pair to the object † delete: Deletes a (key, value) pair from the object † lookup: Given a key, retrieves the value associated with that key fromthe object †^ Later, define new object (Search_Object_2) that additionallyallows traversing (key, value) pairs in sorted order^ „^ Supported operations for Search_Object_2:^ †^ All of above, plus:^ †^ rewind:

returns us to beginning † next: returns next (key, value) pair „^ Accomplish this by having Search_Object_2 inheritSearch_Object_1’s interface

Example of Implementation Inheritance^ †^ Suppose:^ „^ Search_Object_1 is implemented using binarysearch tree^ „^ You already have a binary search treeimplemented, including implementations for theprevious operations, but using different names^ †^ To inherit binary search tree implementation, wemake Search_Object_1 be a subclass of thebinary tree.^ „^ We then make the insert, delete, and lookupoperations call the appropriate binary treeoperations

More detailed look at Object Orientation…^ 1. Object^ 2. Class^ 3. Attributes^ 4. Operation^ 5. Interface (Polymorphism)^ 6. Generalization Relationships

1.^ What is an Object? †^ An object is a “smart” data structure^ „^ Set of state variables^ „^ Set of methods for manipulating state variables † Examples –

physical, conceptual, or software entities: „ Physical entity: „ Conceptual entity: „ Software entity:

robot chemical processlinked list data structure

An Object Has State †^ The state of an object is one of the possibleconditions in which an object may exist †^ The state of an object normally changes overtime †^ Represented by: Attribute values + Links(relationship instances) Object:^ L. Parker^

L. Parker Name: (^9738239) Employee ID: Aug. 1, 2002 Date hired: Teaching Status:

An Object Has Behavior †^ Behavior determines how an object acts andreacts to requests from other objects †^ Behavior is represented by the set of messagesit can respond to (i.e., the operations theobject can perform)

Add me to CS302 with L. Parker (Returns: confirmation) Registration System

CS302 Course