abstraction, interface,...
TRANSCRIPT
Abstraction, Interface, Implementation
Abstraction
• Abstraction, simply mean, hiding out details
• Can be applied anywhere complexities needs to be handled
• We try to have a view which is relevant to us “for the purpose”, while hiding other details
• We do apply some kind of abstraction in every walk of life.
Abstraction applied to provide Average man’s view of Automobile
Abstraction
• Can be applied at different level, for different purposes
• Viewing of atlas-– Different zoom level, details making view are hidden– Different view are created for different purposes
• In programming, abstraction helps in handling complexities of software development
Abstraction in Programming
• Abstraction has been important technique in programming much before OOP.
• Abstraction plays pivotal role in “divide and conquer”strategy– decompose such that you have some meaning abstract view of a
sub-program or module while hiding its internal details
• Abstraction has been important technique in Identifying– procedures and module– their responsibilities– interface to use– Input and output, and so on
• All boils down to hiding details
Abstraction in Programming
• While abstraction is a theoretical concept, programming languages implement it through encapsulation, and allows you to use data and apply operations on it in abstract way
• For example, you only need to know abstract meaning of integer in order to use it in a C program, you do not have to know how it is stored in memory, i.e. how it has been implemented
Programming languages have been evolved around abstraction
• Assembly language provide abstraction view of machine instruction
• High Level languages provided abstract support for primitive data types supporting arithmetic operations
• C provided better abstraction for functions, and modules
• OOP languages are much ahead …
Abstraction in OOP
• At highest level in OOP, a program is viewed as community of objects, interacting with each other contributing towards common objective
Abstraction in OOP
• At this level abstraction is applied in order to establish line of communication and cooperation needs to take place between objects in order to accomplish common goal
Abstraction in OOP
• Next level of abstraction is grouping related objectstogether
• Grouping is done based on contribution of objects towards a common goal.
• This arrangement is known as packages in Java, namespaces in C++
Abstraction in OOP
• Further down, next level of abstraction deal with the interaction between two individual objects – Client and Server abstraction
• Often we speak of objects as providing as providing service to other objects, her we carry on with the notion by describing interaction communication as an interaction between client and server
• Object taking service from another object is client while object serving the request is known as server
Abstraction in OOP
• At this level of abstraction, from client point of view, server services are described -– What services
the server offers– How client can
get this services– What is deliverable
of each service
• While server point of view, what data structure is required to serve the client needs, how tasks are to be performed, and so on
Clients View of Server
Interface and Implementation
• Client’s view is called as Interface while developers view is called as Implementation
• An interface tells what service a software component provides, and how client can get those services, what info the client is to submit along with the request, and what the service will deliver to it.
• Implementation provides computing elements to perform services claimed by the software component
Abstraction and Encapsulation
• Programming languages provide encapsulationmechanism to hide implementation view of Abstract Data Types
• Encapsulation, while hides implementation details from client, greatly eases developers by providing implementation independence
• Developer can change implementation- change could be for efficiency, cost, reliability, or any other issue
• Example Implementation Independence
Abstraction and EncapsulationWhat should be hidden
• User’s view is understood well and whatever is required in order to use the software component are made visible as part of interface
• Rule of thumb 1: ask a question, does user need to know this in order to use the component, if no, hide it
• Rule 2, read it- “state of the object changes when some operations is applied on to it”, state of the object should not directly be modified by the user – make fields private
Abstraction in OOP
• While developing object oriented software development, we apply some more forms of abstraction, below are two most common among others -
– Specialization/ generalzation – that gives us class hierarchy. IS-A abstraction
– Division into parts- that helps in identifying composition classes. HAS-A abstraction
Abstraction in OOP
• We have seen various levels of abstraction –– System as community of objects– Grouping the objects– Client server view of objects– IS-A and HAS-A abstraction
• Each level abstraction is important during software development.
• In fact, software designer often move back and forth between different level of abstractions
Abstract Data Types
• Inspired by usage of primitive data types
• Developers, not only must be able to have similar abstract usage of user defined data types, but also able to apply operations without knowing how the operations are supported by the data type
• An, abstract data type is specified by abstract specifications.
• Separation of interface and implementation is important advancement in creating abstract data types.
Abstract Data Types
• Abstract data type still is a theoretical concept, classes, or modules in general are ways of creating abstract data types
• Typically we do following things while creating abstract data types-– Specify and Export (make public) interface– Define (implement) operations supported by the data
type– Protect the data associated with the type so that they
can be operated only through operations– Allow having multiple instances of the type
• You can do many of these things even in C, therefore you could define Abstract Data Type even before OOP
Abstract Data Types
• In conclusion:
Abstract Data Types allows you to program for abstract views of data types without knowing their implementation
References
• Chapter 2,Introduction to object-oriented programming,Timothy Budd, Pearson
• Chapter 3, Object Oriented Design and Patterns,Cay S Horstmann, John Wiley & Sons
Thanks