CSC/ECE 517 Fall 2009/wiki2 15 sm: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 18: Line 18:


*Implementation - That part of the program thet defines the program component.
*Implementation - That part of the program thet defines the program component.
The interaction between these two entities is usually restricted to a specific interface.  
The interaction between these two entities is usually restricted to a specific interface.Most of the modern object-oriented languages provide access to only a set of public operations on an object.




Line 28: Line 28:
There are two kinds of abstraction :
There are two kinds of abstraction :


*Procedural Abstraction
*Procedural Abstraction - This is one of the oldest abstraction mechanisms.The program making a function call is considered as a client and the function body consisting of instructions executed each time the function is called is considered as the implementation.For Example: a code that stores the square root of a variable x in the variable y can be encapsulated into a function.By doing this,an interface which consists of a function name, the input parameters and the type of output are defined.It provides a kind of information hiding since the information about the underlying functionalities is contained in the function declaration but hidden from the program using that function.The function can be called on different arguments.In short ,we can say that the code can be made generic as well as reusable by enclosing it inside a function .


*Data Abstraction
*Data Abstraction - The concept of data abstraction refers to hiding the information about the way data is represented.The mechanisms used for data abstraction are abstract data type declarations and modules.By data abstraction,an interface of the data structure can be identified.It also helps in information hiding by the separation of implementation decisions from those parts of the program that are using the data structure.It provides the reusability of data structure by many different programs.An abstract data type provides a specific interface to be used by other parts of a program.It also makes sure that it can only be used through its interface by restricting access to it.


*Generic Abstractions - In typed programming languages,different codes are written for stacs of integers and stacks of strings.So,different type declarations for different versions of stacks are compiled to code allocating different amount of space for local variables.Since the code for different versions of stacks for different types of elements are identical,these languages have incorporated some form of type parameterization.
='''Implementation of Abstraction in Object-Oriented Languages'''=






='''Implementation of Abstraction in Object-Oriented Languages'''=
Traces of data abstraction appeared in the class construct of Simula 67.Simula is considered as the first object oriented programming language.Simula does not have the concept of abstract classes since classes with pure virtual methods can be instantiated.But,It provided encapsulation of the class construct.The variables declared in a Simula67 class are not hidden from the clients  that are creators of the objects of that class.Ada is another language that does provide encapsulation and can be used to simulate abstract data types.These encapsulation constructs are known as packages.Packages can be written with a separate interface called package specification and the implementation is calle package body.Modula-2 uses modules instead of packages used in Ada to provide support for abstract data types.In Modula ,a module interface is known as a definition module and an implementation ,an implementation module..Another object oriented language that can be considered is Beta which is a modern object oriented language providing powerful abstraction mechanisms.These mechanisms include support for identification of objects ,classification and composition. It is a strongly typed language with mechanisms such as class,procedure,function,process,exception all put together into a single  abstraction mechanism called as pattern.Eiffel is another language whose design is closely based on OOP theory with a formal support for abstract data types.






Data Abstraction appeared in the class construct of Simula 67.The classs in Simula are created dynamically.It provided encapsulation of the class construct.The variables declared in a Simula67 class are not hidden from the clients  that are creators of the objects of that class.Ada does provide encapsulation that can be used to simulate abstract data types.These encapsulation constructs are known as packages.Modula-2 uses modules instead of packages used in Ada to provide support for abstract data types except that the types whose representations are hidden inside must be pointers.


='''Uses'''=
='''Uses'''=

Revision as of 05:41, 8 October 2009

Abstraction and the Object Model

Introduction

Abstraction is a process in which some characteristics of an entity are removed to reduce it to a set of essential characteristics that can effectively define that entity.It is basically done to reduce complexity.For example : the abstraction of a plastic container to a container will retain only the general information on the behavior and attributes of the container.The principle of abstraction is an essential element of Object-Oriented programming.One of the most powerful ways of managing abstraction is by using hierarchical classifications.This helps in layering the semantics of complex systems thus breaking them into chunks of manageable pieces.This method of hierarchical abstractions can also be applied to computer programs.The data from a process-oriented program can be transformed into its component objects using the principle of abstraction.In programming languages,abstraction is a mechanism that emphasizes the general properties of some segment of code and hides details.It involves separating a program into parts that contains certain details and parts where these details are hidden.In Object-Oriented terminology,data is considered as attributes and the functions are referred to as methods.The main advantage of Object-Oriented programming is that the data as well as the operations that manipulate the data which is called code,are both encapsulated inside the object.For example : a Java Applet is an object.The browser executing that particular objet has no idea about its functionalities.When the object is loaded ,the code inside it is executed by the browser using the data contained within that particular object.Objects are the building blocks of Object Oriented programming.The state of an object is the data contained inside that object also referred to as attributes.These attributes help in differentiating between the various objects.In object-oriented programming,the methods define the behaviour of an object.The concept of getters and setters sometimes referred to as accessor methods provide controlled access to an object's data. A class is a kind of template from which objects are made.For example: if we are creating two employess,it is said that we have created to instances of the employee class with each instance or object having its own attributes and methods.An object can be instantiated or built only by using a class. For Example: To instantiate an object in java ,

                  myClass myObject;

Here myClass is a class and myObject is an object.

Overview

There are two common terms associated with the term abstraction:

  • Client - that part of the program that uses the program component.
  • Implementation - That part of the program thet defines the program component.

The interaction between these two entities is usually restricted to a specific interface.Most of the modern object-oriented languages provide access to only a set of public operations on an object.



Types of Abstraction

There are two kinds of abstraction :

  • Procedural Abstraction - This is one of the oldest abstraction mechanisms.The program making a function call is considered as a client and the function body consisting of instructions executed each time the function is called is considered as the implementation.For Example: a code that stores the square root of a variable x in the variable y can be encapsulated into a function.By doing this,an interface which consists of a function name, the input parameters and the type of output are defined.It provides a kind of information hiding since the information about the underlying functionalities is contained in the function declaration but hidden from the program using that function.The function can be called on different arguments.In short ,we can say that the code can be made generic as well as reusable by enclosing it inside a function .
  • Data Abstraction - The concept of data abstraction refers to hiding the information about the way data is represented.The mechanisms used for data abstraction are abstract data type declarations and modules.By data abstraction,an interface of the data structure can be identified.It also helps in information hiding by the separation of implementation decisions from those parts of the program that are using the data structure.It provides the reusability of data structure by many different programs.An abstract data type provides a specific interface to be used by other parts of a program.It also makes sure that it can only be used through its interface by restricting access to it.
  • Generic Abstractions - In typed programming languages,different codes are written for stacs of integers and stacks of strings.So,different type declarations for different versions of stacks are compiled to code allocating different amount of space for local variables.Since the code for different versions of stacks for different types of elements are identical,these languages have incorporated some form of type parameterization.


Implementation of Abstraction in Object-Oriented Languages

Traces of data abstraction appeared in the class construct of Simula 67.Simula is considered as the first object oriented programming language.Simula does not have the concept of abstract classes since classes with pure virtual methods can be instantiated.But,It provided encapsulation of the class construct.The variables declared in a Simula67 class are not hidden from the clients that are creators of the objects of that class.Ada is another language that does provide encapsulation and can be used to simulate abstract data types.These encapsulation constructs are known as packages.Packages can be written with a separate interface called package specification and the implementation is calle package body.Modula-2 uses modules instead of packages used in Ada to provide support for abstract data types.In Modula ,a module interface is known as a definition module and an implementation ,an implementation module..Another object oriented language that can be considered is Beta which is a modern object oriented language providing powerful abstraction mechanisms.These mechanisms include support for identification of objects ,classification and composition. It is a strongly typed language with mechanisms such as class,procedure,function,process,exception all put together into a single abstraction mechanism called as pattern.Eiffel is another language whose design is closely based on OOP theory with a formal support for abstract data types.



Uses

  • Flexibility - It provides flexibility since the programmer can now hide the details or data that are not required for presentation.
  • More security - It helps in hiding the implementation details and giving access only to the data.
  • Modularity - It helps a user to divide a large program into chunks of modules.This helps in making the debugging as well as testing a lot more easier.
  • Easy replacement - It is easier to replace code without recompiling.



Links