DISHA NIRDESHAN

Enlightens your career

Tuesday, June 21, 2011

Other Concepts


Other Concepts:

What is an Object? What is Object Oriented Programming?

Object represents/resembles a Physical/real entity. An object is simply something you can give a name. Object Oriented Programming is a Style of programming that represents a program as a system of objects and enables code-reuse.

 

What are C++ storage classes?

auto:the default. Variables are automatically created and initialized when they are defined and are destroyed at the end of the block containing their definition(when they are out of scope). They are not visible  outside that block
       

auto int a;
         int b; Both are same statement. auto is default register: a type of auto variable. a suggestion to the compiler to use a CPU register for performance(Generally Used in loops)
static:a variable that is known only within the  function that contains its definition but is never destroyed and retains its value between calls to that function. It exists from the time the program begins execution

     void example()
    { 
        static int a = 0; // static variable  
        a++;
        cout << a <<endl;
   }

   If this function is called 10 times, the output will be 1,2,3,4...etc., The value of the variable a is preserved through function calls.    If this static variable is declared as a member of a class, then it will preserve the value for all the objects of the class.i.e, one copy of this data variable will be shared by all objects of the class

What is a scope resolution operator?

A scope resolution operator (::), can be used to define the member functions of a class outside the class.

 

 

 

Association :

Association is a relationship where all object have their own lifecycle and there is no owner. Let's take an example of Teacher and Student. Multiple students can associate with single teacher and single student can associate with multiple teachers but there is no ownership between the objects and both have their own lifecycle. Both can create and delete independently.


Aggregation:

 Aggregation is a specialize form of Association where all object have their own lifecycle but there is ownership and child object cannot belongs to another parent object. Let's take an example of Department and teacher. A single teacher cannot belongs to multiple departments, but if we delete the department teacher object will not destroy. We can think about "has-a" relationship.

Composition:

 Composition is again specialize form of Aggregation and we can call this as a "death" relationship. It is a strong type of Aggregation. Child object does not have their lifecycle and if parent object deletes all child object will also be deleted. Let's take again an example of relationship between House and rooms. House can contain multiple rooms there is no independent life of room and any room cannot belongs to two different house if we delete the house room will automatically delete. Let's take another example relationship between Questions and options. Single questions can have multiple options and option can not belong to multiple questions. If we delete questions options will automatically delete.

 

 


0 comments :