abstraction cmps 2143. 2 abstraction abstraction mechanisms are techniques to deal with creating,...

14
Abstraction CMPS 2143

Upload: francine-fleming

Post on 05-Jan-2016

244 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Abstraction CMPS 2143. 2 Abstraction Abstraction mechanisms are techniques to deal with creating, understanding and managing complex systems Abstraction

Abstraction

CMPS 2143

Page 2: Abstraction CMPS 2143. 2 Abstraction Abstraction mechanisms are techniques to deal with creating, understanding and managing complex systems Abstraction

2

Abstraction

•Abstraction mechanisms are techniques to deal with creating, understanding and managing complex systems

•Abstraction is the purposeful suppression or hiding of some details of a process or artifact in order to bring out more clearly other aspects, details or structures

•Through abstraction one builds a model of the actual system

Page 3: Abstraction CMPS 2143. 2 Abstraction Abstraction mechanisms are techniques to deal with creating, understanding and managing complex systems Abstraction

3

Page 4: Abstraction CMPS 2143. 2 Abstraction Abstraction mechanisms are techniques to deal with creating, understanding and managing complex systems Abstraction

4

Abstraction in Structured Programmingvoid main (){ ifstream infile; ofstream outfile; Container container;

openFiles (infile, outfile); while moreData (infile) getData (infile, container); organizeData (container); displayData (container); closeFiles (infile, outfile);}

Page 5: Abstraction CMPS 2143. 2 Abstraction Abstraction mechanisms are techniques to deal with creating, understanding and managing complex systems Abstraction

5

Another way to think of abstraction

•Factoring out redundancy

▫Use loops▫Use functions (in structured programming)▫Use Abstract Data Types (ADTs)▫Use classes (in OOP)

http://en.wikipedia.org/wiki/Duplicate_code

Page 6: Abstraction CMPS 2143. 2 Abstraction Abstraction mechanisms are techniques to deal with creating, understanding and managing complex systems Abstraction

6

Abstraction layers in OOP•At the highest level a program is

viewed as a community of cooperating objects.

•Each object in this community provides services

•At this highest level the important features are the services provided by each object and the lines of cooperation and communication between them.

Page 7: Abstraction CMPS 2143. 2 Abstraction Abstraction mechanisms are techniques to deal with creating, understanding and managing complex systems Abstraction

7

Abstraction layers in OOP•The next level of abstraction

allows a group of objects working together to be grouped in a unit (packages, name spaces, units) allowing some names to be exposed to the world outside the unit while others remain hidden inside the unit

library.dll

Page 8: Abstraction CMPS 2143. 2 Abstraction Abstraction mechanisms are techniques to deal with creating, understanding and managing complex systems Abstraction

8

Abstraction layers in OOP•The next two levels of abstraction deal with the

interaction between 2 individual objects where one (the client) uses services from the other (the server)▫Server code advertises the services it can provide for the client

as an interface (Java) or .h file (C++) and provides a concrete implementation for its interface

▫Client code programs to this interface

http://docs.oracle.com/javase/7/docs/api/java/util/Stack.html

import java.util.*;

Stack intStack = new Stack();intStack.push (“data”);

Page 9: Abstraction CMPS 2143. 2 Abstraction Abstraction mechanisms are techniques to deal with creating, understanding and managing complex systems Abstraction

9

Abstraction layers in OOP•The last level of abstraction considers a single task in

isolation, that is which steps implement a single method

public class Stack implements IStack ..{ : public void push(E e) { if top == MAX) throw new FullStackException(); items[++top] = e; } :}

Page 10: Abstraction CMPS 2143. 2 Abstraction Abstraction mechanisms are techniques to deal with creating, understanding and managing complex systems Abstraction

10

General Forms of Abstraction

abstraction division into parts“has a”

multiple views

Specialisation“is a”

catalogs

repetition

service view

class hierachies ADT

OO programs

patterns

composition

recursive data structures

recursive algorithms

dictionaries

cross-references

Page 11: Abstraction CMPS 2143. 2 Abstraction Abstraction mechanisms are techniques to deal with creating, understanding and managing complex systems Abstraction

11

Abstraction mechanisms in programming languages•Procedures and Functions (function centered view)

+ information hiding for the detail of the behavior- no information hiding for the detail of the data- no encapsulation

•Modules and Packages (data centered view)+ information hiding+ encapsulation- instantiation not always supported

•Abstract Data Types+ separates interface and implementation

Page 12: Abstraction CMPS 2143. 2 Abstraction Abstraction mechanisms are techniques to deal with creating, understanding and managing complex systems Abstraction

12

Abstraction mechanisms in OO programming languages

•Classes are as Abstract Data Types in a service-centered view

•Message Passing and Method Binding bring polymorphism leading to more readable code

•Class Hierarchies and Inheritance bring code sharing which results in increased functionality and reduction of code size

• Inheritance and polymorphism together allow for tailoring shared code

Page 13: Abstraction CMPS 2143. 2 Abstraction Abstraction mechanisms are techniques to deal with creating, understanding and managing complex systems Abstraction

13

Object Oriented Design

•Object oriented software development is NOT about the syntax of a programming language

•Object oriented software development is about a design technique driven by the determination and delegation of responsibilities

•Responsibility implies non-interference, it cuts or reduces the links between objects that depend on implementation details

•Goes beyond information hiding and encapsulation when dealing with programming in the large