Professional Documents
Culture Documents
UNIT I
Abstract Data Types :
A data type can be considered abstract when it is defined in terms of operations on it, and
its implementation is hidden (so that we can always replace one implementation with
another for and this will not interfere with anything in the program). Thus, speaking
about such a type, we leave its implementation aside considering it irrelevant to the topic,
unless we directly discuss the implementation.
Most Object Oriented Languages provide the feature of user-defined abstract data types.
In C++ it can be done with a class which has no public/protected data members (only
privates), nor friends, nor any methods which return pointers/references to any of the
private fields.
You're well acquainted with data types by now, like integers, arrays, and so on. To access
the data, you've used operations defined in the programming language for the data type,
for instance by accessing array elements by using the square bracket notation, or by
accessing scalar values merely by using the name of the corresponding variables.This
approach doesn't always work on large programs in the real world, because these
programs evolve as a result of new requirements or constraints.
It is useful to separate the use of a data structure from the details of its implementation.
This is the principle underlying the use of abstract data types.
Here are some examples.
Stack : operations are "push an item onto the stack", "pop an item from the stack", "ask if
the stack is empty"; implementation may be as array or linked list or whatever.
Queue : operations are "add to the end of the queue", "delete from the beginning of the
queue", "ask if the queue is empty"; implementation may be as array or linked list or
heap.
Search structure : operations are "insert an item", "ask if an item is in the structure", and
"delete an item"; implementation may be as array, linked list, tree, hash table.
Private (or class-private) restricts the access to the class itself. Only methods that are part of
the same class can access private members.
Protected (or class-protected) allows the class itself and all its subclasses to access the
member.
Public means that any code can access the member by its name.
Although many object-oriented languages support the above access specifiers, their semantics
may differ.
Object-oriented design uses the access specifiers in conjunction with careful design of public
method implementations to enforce class invariantsconstraints on the state of the objects. A
common usage of access specifiers is to separate the internal data of a class from its interface:
the internal structure is made private, while public access or methods can be used to inspect or
alter such private data.
Access specifiers do not necessarily control visibility, in that even private members may be
visible to client external code. In some languages, an inaccessible but visible member may be
referred to at run-time (for example, by a pointer returned from a member function), but an
attempt to use it by referring to the name of the member from client code will be prevented by
the type checker.
The various object-oriented programming languages enforce member accessibility and visibility
to various degrees, and depending on the language's type system and compilation policies,
enforced at either compile-time or run-time. For example, the Java language does not allow
client code that accesses the private data of a class to compile. In the C++ language, private
methods are visible, but not accessible in the interface; however, they may be made invisible by
explicitly declaring fully abstract classes that represent the interfaces of the class.
Object :
In computer science, an object is a location in memory having a value and possibly referenced by
an identifier. An object can be a variable, a data structure, or a function. In class-based objectoriented programming paradigm, "object" refers to a particular instance of a class where the
object can be a combination of variables, functions, and data structures. In
relational database management, an object can be a table or column, or an association between
data and a database entity (such as relating a person's age to a specific person).
An important concept for objects is the design pattern. A design pattern provides a reusable
template to address a common problem. The following object descriptions are examples of some
of the most common design patterns for objects.
Function object: an object with a single method (in C++, this method would be the
function operator, "operator( )") that acts much like a function (like a C/C++ pointer to a
function).
Immutable object: an object set up with a fixed state at creation time and which does not
change afterward.
Metaobject: an object from which other objects can be created (Compare with class,
which is not necessarily an object)
Prototype: a specialized metaobject from which other objects can be created by copying
God object: an object that knows too much or does too much. The God object is an
example of an anti-pattern.
Singleton object: An object that is the only instance of its class during the lifetime of the
program.
Filter object