Monday, February 1, 2016

Basic concepts when it comes to OOPs...


"classes and objects" is the base when it comes to OOP
classes in C++ are very similar to structures in C

Important points
  1. class members
  2. access modifiers
  3. constructor (eg. classname(){...})
  4. destructor (eg. ~classname(){...})
  5. copy constructor
  6. friend function
  7. inline function
  8. 'this' pointer

Concepts / Aspects / Features :
  1. Inheritance (parent/base class & child/derived class)
  2. Overloading - (The definition of the function must differ from each other by the types and/or the number of arguments in the argument list. You can not overload function declarations that differ only by return type.)
    • function overloading
    • operator overloading (important aspect of C++)
    • overload resolution
  3. Polymorphism (functions with same name but different data types of input parameters and/or return types)
    • static resolution / static linkage / early binding (the call of the function is being set once by the compiler as the version defined in the base class)
    • Virtual function - keyword 'virtual': (the compiler looks at the contents of the pointer instead of it's type) - dynamic linkage / late binding
      • Pure Virtual Function (eg. virtual int area() = 0; //The = 0 tells the compiler that the function has no body and above virtual function will be called pure virtual function.)
  4. Abstraction
    • interfaces
    • implementations
  5. Encapsulation (public, private, protected)
    • data encapsulation (data hiding)
    • data abstraction
  6. Interfaces
    • abstract class (class with at least one Pure Virtual function.  The purpose of an abstract class is to provide an appropriate base class from which other classes can inherit. Abstract classes cannot be used to instantiate objects and serves only as an interface.  )
A step further...
  1. namespaces
    • defining namespaces
    • using namespaces
    • Dis-contiguous namespaces
    • Nested namespaces
  2. templates (A template is a blueprint or formula for creating a generic class or a function. The library containers like iterators and algorithms are examples of generic programming and have been developed using template concept.)
    • function template: typename
    • class template: class
  3. dynamic memory
    • new (eg. float *f1 = new float;) - The malloc() function from C, still exists in C++, but it is recommended to avoid using malloc() function. The main advantage of new over malloc() is that new doesn't just allocate memory, it constructs objects which is prime purpose of C++.
    • delete
  4. exception handling
    • try
    • throw
    • catch
  5. files and streaming
    • ofstream - create and write to file
    • ifstream - read information from file
    • fstream - capability of both ofstream and ifstream
    • open()
    • close()
  6. signal  handling
    • signal() - to trap unexpected events
    • raise() - generate signals
  7. multi threading
    • create thread
    • terminate thread
    • passing arguments to thread
    • join thread
    • detach thread

No comments:

Post a Comment

PROFILE

My photo
India
Design Engineer ( IFM Engineering Private Limited )

Followers