CSC/ECE 517 Fall 2009/wiki2 15 sm
Abstraction and the Object Model
Abstraction
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 behaviour 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.
Object Model
Implementation of Abstraction in Object-Oriented Languages
Java
while declaring an abstract class in Java, some of the methods in that particular class can be left unimplemented.Those methods are indicated with the keyword "abstract".These methods are sometimes referred to as subclasser responsibility since they have no implementation specified in the superclass. The method is defined using the following syntax:
abstract type name(parameter-list);
For Example :
public abstract class AbstractClass { public String toString() {return "An AbstractClass object";} public abstract void visit(Object o); }
The above example has one implemented and one non-implemented abstract method.The declaration of an unimplemented method is similar to the way methods are declared in an interface.The difference is the addition of the "abstract" keyword.An abstract class is said to be totally abstract if it contains all the unimplemented methods.Such a class can extend at most one superclass of Java.There can be no objects of an abstract class which means that an abstract class cannot be instantiated directly with the new operator.Abstract static methods or abstract constructors cannot be declared.A subclass of an abstract class must either implement all of the abstract methods in the superclass ,or should be declared abstract.