You are on page 1of 5

CS- 403 Object Oriented Technology

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.

Shri Yogindra Sagar Institute of Technology & Science, Ratlam


Computer Science Dept.

CS- 403 Object Oriented Technology

An algorithm is an abstract idea, and a program is an implementation of an algorithm.


Similarly, it is useful to be able to work with the abstract idea behind a data type or data
structure, without getting bogged down in the implementation details. The abstraction in this
case is called an "abstract data type".
An abstract data type specifies the values of the type, but not how those values are represented as
collections of bits, and it specifies operations on those values in terms of their inputs, outputs,
and effects rather than as particular algorithms or program code.
An abstract data type is a type with associated operations, but whose representation is hidden.
Common examples of abstract data types are the built-in primitive types in Haskell, Integer and
Float. In many cases it is not necessary to completely hide the representation of data, so a normal
data type definition is sufficient.

Objects & Classes :


Classes :
In object-oriented programming, a class is an extensible program-code-template for
creating objects, providing initial values for state (member variables) and implementations of
behavior (member functions, methods). In many languages, the class name is used as the name
for the class (the template itself), the name for the default constructor of the class
(subroutine that creates objects), and as the type of objects generated by the type, and these
distinct concepts are easily conflated.
When an object is created by a constructor of the class, the resulting object is called
an instance of the class, and the member variables specific to the object are called instance
variables, to contrast with the class variables shared across the class.
In some languages, classes are only a compile-time feature (new classes cannot be declared at
runtime), while in other languages classes are first-class citizens, and are generally themselves
objects (typically of type Class or similar). In these languages, a class that creates classes is
called a metaclass.

Shri Yogindra Sagar Institute of Technology & Science, Ratlam


Computer Science Dept.

CS- 403 Object Oriented Technology

The following is a common set of access specifier :

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.

Shri Yogindra Sagar Institute of Technology & Science, Ratlam


Computer Science Dept.

CS- 403 Object Oriented Technology

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.

First-class object: an object that can be used without restriction.

Container: an object that can contain other objects.

Factory object: an object whose purpose is to create other objects.

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

Shri Yogindra Sagar Institute of Technology & Science, Ratlam


Computer Science Dept.

CS- 403 Object Oriented Technology

Shri Yogindra Sagar Institute of Technology & Science, Ratlam


Computer Science Dept.

You might also like