Wednesday, August 4, 2010

Object Oriented Programming 1-2

  1. What is an accessor?

An accessor is a class operation that does not modify the state of an object. The accessor functions need to be declared as const operations

 

  1. What is an inspector?

Messages that return the value of an attribute are called inspector.

 

  1. What is a modifier?

A modifier, also called a modifying function is a member function that changes the value of at least one data member. In other words, an operation that modifies the state of an object. Modifiers are also known as ‘mutators’.

 

  1. What is a predicate?

A predicate is a function that returns a bool value.

  1. What is a facilitator?

A facilitator causes an object to perform some action or service.

 

  1. State the "Rule of minimality" and its corollary?

The rule of minimality states that unless a behavior is needed, it shouldn't be part of the ADT.

Corollary of the rule of minimality: If the function or operator can be defined such that, it is not a member. This practice makes a non-member function or operator generally independent of changes to the class's implementation.

 

  1. What is reflexive association?

The 'is-a' is called a reflexive association because the reflexive association permits classes to bear the is-a association not only with their super-classes but also with themselves. It differs from a 'specializes-from' as 'specializes-from' is usually used to describe the association between a super-class and a sub-class.

For example: Printer is-a printer.

 

  1. What is slicing?

Slicing means that the data added by a subclass are discarded when an object of the subclass is passed or returned by value or from a function expecting a base class object.

Consider the following class declaration:

class base{



base& operator =(const base&);

base (const base&);

}

void fun( ){

base e=m;

e=m;

}

As base copy functions don't know anything about the derived only the base part of the derived is copied. This is commonly referred to as slicing. One reason to pass objects of classes in a hierarchy is to avoid slicing. Other reasons are to preserve polymorphic behavior and to gain efficiency.

 

  1. What is a Null object?

It is an object of some class whose purpose is to indicate that a real object of that class does not exist. One common use for a null object is a return value from a member function that is supposed to return an object with some specified properties but cannot find such an object.

 

  1. Define precondition and post-condition to a member function.

Precondition:

A precondition is a condition that must be true on entry to a member function. A class is used correctly if preconditions are never false. An operation is not responsible for doing anything sensible if its precondition fails to hold.

For example, the interface invariants of stack class say nothing about pushing yet another element on a stack that is already full. We say that isful() is a precondition of the push operation.

Post-condition:

A post-condition is a condition that must be true on exit from a member function if the precondition was valid on entry to that function. A class is implemented correctly if post-conditions are never false.

For example, after pushing an element on the stack, we know that isempty() must necessarily hold. This is a post-condition of the push operation.

 

  1. What is class invariant?

A class invariant is a condition that defines all valid states for an object. It is a logical condition to ensure the correct working of a class. Class invariants must hold when an object is created, and they must be preserved under all operations of the class. In particular all class invariants are both preconditions and post-conditions for all operations or member functions of the class.

 

  1. What are the conditions that have to be met for a condition to be an invariant of the class?
    • The condition should hold at the end of every constructor

      The condition should hold at the end of every mutator(non-const) operation.
  1. What are proxy objects?

Objects that points to other objects are called proxy objects or surrogates. Its an object that provides the same interface as its server object but does not have any functionality. During a method invocation, it routes data to the true server object and sends back the return value to the object. template<class T> class Array2D{

public:

class Array1D{

public:

T& operator[] (int index);

};

Array1D operator[] (int index);

const Array1D operator[] (int index) const;

};

The following then becomes legal:

Array2D<float>data(10,20);

cout<<data[3][6]; // fine

Here data[3] yields an Array1D object and the operator [] invocation on that object yields the float in position(3,6) of the original two dimensional array. Clients of the Array2D class need not be aware of the presence of the Array1D class. Objects of this latter class stand for one-dimensional array objects that, conceptually, do not exist for clients of Array2D. Such clients program as if they were using real, live, two-dimensional arrays. Each Array1D object stands for a one-dimensional array that is absent from a conceptual model used by the clients of Array2D. In the above example, Array1D is a proxy class. Its instances stand for one-dimensional arrays that, conceptually, do not exist.

  1. What is cloning?

An object can carry out copying in two ways i.e. it can set itself to be a copy of another object, or it can return a copy of itself. The latter process is called cloning.

 

  1. List out some of the OODBMS available.
    • GEMSTONE/OPAL of Gemstone systems.
    • ONTOS of Ontos.
    • Objectivity of Objectivity inc.
    • Versant of Versant object technology.
    • Object store of Object Design.
    • ARDENT of ARDENT software.
    • POET of POET software.

No comments:

Post a Comment