data abstraction

12
Data Abstraction Data Abstraction

Upload: clinton-burnett

Post on 30-Dec-2015

39 views

Category:

Documents


0 download

DESCRIPTION

Data Abstraction. Object-Oriented Analysis and Design The analysis and design methodology used on most large systems. Gather Requirements They provide: Perception of what the client expcets Description of what a solution must do They do not provide: Design details Implementation details - PowerPoint PPT Presentation

TRANSCRIPT

Data AbstractionData Abstraction

Object-Oriented Analysis and Design◦The analysis and design methodology used on

most large systems

Oblect Oriented AnalysisOblect Oriented Analysis

Gather RequirementsThey provide:

◦Perception of what the client expcets◦Description of what a solution must do

They do not provide:◦Design details◦Implementation details

Problem is expressed in terms of relevant objects and how they interact with one another

Object-Oriented DesignObject-Oriented Design

Description of a high-level solution to the problem discovered during the analysis phase

Solution is expressed in terms of software objects and how they interact

What are Software Objects?What are Software Objects?

A collection of attributes ◦Data members: what do I know

A collection of behaviors◦Methods (or functions): what can I do

Each object (specified as a class)◦Has a single, well-defined task◦If a class/object has too many responsibilities, it

should be split into multiple classes

OO Terms/TechniquesOO Terms/Techniques

Encapsulation: Objects combine data and operations

Inheritance: Classes can inherit properties from another class

Polymorphism: Objects determine appropriate operations at run-time

CPSC 122: Encapsulation only

Operation Contracts◦Documents how a method can be used and

what it’s limitations are◦Does not specify how operations are completed◦Summarized in

Task: what the method does Precondition: statement of the conditions that

must exist at the beginning of the function Postcondition: statement of the conditions at the

end of the function

ExampleExample

/*Task: Sorts and arrayPrecondition: anArray is an array of num integers; num > 0.Postcondition: The integers in anArray are

sorted*/

AbstractionAbstraction

Abstraction separates the purpose of a module from its implementation

If you used sqrt within cmath, you made use of abstraction

Abstraction presents a public face of the object to the user. The private implementation is left to the developer

Data/Information HidingData/Information Hiding

Abstraction specifies a public view It also implies a private view In a nutshell

◦ Your user doesn’t need to know how something is implemented to use it.

OO programming languages provide mechanisms to make implementation and data inaccessible to users

The Walls in the book’s title◦ User program on one side◦ Implementation on the other◦ Communication is through standard/principled channels: a

slit in the wall Prototype/declaration/header

ADTs: Before ObjectsADTs: Before Objects

Abstract Data Type◦Basically an object without inheritance and

polymorphism◦Collection of data and operations on the data.

Consider ADT Bag◦Software that collects things◦Software that operates on the collection

ADT BagADT Bag

Do◦How many items in bag◦Is bag empty◦Add item to bag◦Remove item from bag◦Remove everything from bag◦How many times does a certain kind of item

appear in the bag◦Does the bag contain a specific object◦Display all items in bag