170 likes | 189 Views
Abstraction in Object-Oriented Programming. Procedural Abstraction. Procedural Abstractions organize instructions. Function Power Give me two numbers (base & exponent) I’ll return to you base exponent ??? Implementation ???. Data Abstraction. Data Abstractions organize data. StudentType.
E N D
Procedural Abstraction • Procedural Abstractions organize instructions. Function Power Give me two numbers (base & exponent) I’ll return to you baseexponent ??? Implementation ???
Data Abstraction • Data Abstractions organize data. StudentType Name (string) GPA (num) Letter Grade (char) Student Number (num)
Queue Object Enqueue Is Full Data State Is Empty Dequeue Initialize Behavioral Abstraction • Behavioral Abstractions combine procedural and data abstractions.
The Object-Oriented Paradigm • Instances of behavioral abstractions are known as objects. • Objects have a clear interface by which they send and receive messages (communicate). • OO is a design and approach issue. Just because a language offers object-oriented features doesn’t mean you’re doing OO programming.
1 3 5 2 4 R Information Hiding Information Hiding means that the user has enough information to use the interface, and no more Example: Stick shift We don’t care about the inner workings... We just want to get the car going!
Encapsulation Encapsulation is the grouping of related things together within some structure Item 1 Item 2 Item3
Encapsulation via Algorithms Algorithms encapsulate modules, data, and instructions. Algorithm Procedure Instructions Function Data
Encapsulating Instructions Modules encapsulate instructions. Procedure/Function Instructions Instructions Module call Instructions
Encapsulating Data Records allow us to do this with data Record Field 1 Field 2 Record
Revisiting the Question “Where is the Queue?” • Notice we still have no way of identifying the idea we’re discussing… • The Queue is still in the “ether.” • We’d like to encapsulate the data (regardless of it’s actual representation) with the behavior (modules). • Once we do this, we’ve got a logical entity to which we can point and say, “there it is!”
Encapsulating Data with Methods Abstract data types (ADTs) allow us to encapsulate logically related data and modules Queue Enqueue Data Dequeue
An idea, a concept, an abstraction of the “big picture” It encapsulates the abstract behaviors and dataimplied by the thing being modeled. Abstract Data Types Queue Enqueue Is Full Data State Is Empty Dequeue Initialize
Achieving Behavioral Abstraction • Abstract data types (ADTs) are concepts. • We require some way to implement these common abstractions so we can write them once, verify that they are correct, and reuse them. • This would save us from having to re-do work. For example, every time we create a queue we did: • List_Node definesa ...q_front isoftype ...q_tail isoftype ... • procedure Enqueue(...) • procedure Dequeue(...) • We need an algorithmic construct that will allow us to bundle these things together… the class.
OO Summary • Behavioral abstraction combines data abstraction with procedural abstraction. • The object-oriented paradigm focuses on the interaction and manipulation of objects. • An Abstract Data Type (ADT) allows us to think of what we’re representing as a thing regardless of it’s actual implementation.