abstraction cmps 2143. 2 abstraction abstraction mechanisms are techniques to deal with creating,...
TRANSCRIPT
Abstraction
CMPS 2143
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
3
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);}
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
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.
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
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”);
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; } :}
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
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
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
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