• Streams & Subjects

    Streams & Subjects

    Get detailed description of each and every topic with proper examples including text, images and videos.

  • Latest Technologies

    Latest Technologies

    Know more about the latest and new emerging technologies and boost your knowledge.

  • Programming

    Programming

    Don't learn just codes and syntax, instead learn the best and efficient way of coding.

  • Technologies

    New Technologies

    Get instant and relevant updates of the latest emerging technologies of lots of streams including web, clouds, virtualization, etc.

  • Freewares

    Freewares

    Download free trials and freewares of various fields and check out their efficiency before buying.

  • Multimedia

    Multimedia

    Learn techniques to design amazing and creative multimedia designs and characters including 2D & 3D layout with rendering.

Showing posts with label OOPS Tutorial. Show all posts
Showing posts with label OOPS Tutorial. Show all posts

Object Lifetime

The object lifetime (or life cycle) of an object in object-oriented programming is the time between an object's creation (also known as instantiation or construction) till the object is no longer used, and is destructed or freed.

Code to create object:
Employee *employeePtr;
employeePtr = new Employee;

Code to destroy object:
delete employeePtr;
employeePtr = NULL;


Read more

Methods

A method is a subroutine (or procedure) associated with a class. Methods define the behavior to be exhibited by instances of the associated class at program run time. Methods have the special property that at runtime, they have access to data stored in an instance of the class (or class instance or class object or object) they are associated with and are thereby able to control the state of the instance. The association between class and method is called binding. A method associated with a class is said to be bound to the class. Methods can be bound to a class at compile time (static binding) or to an object at runtime (dynamic binding).

Example
The following java code defines a method "rectangle" in the class "main" that can find area of a rectangle.
public class Main
{
int rectangle(int h,int w)
{
return h*w;
}
}


Read more

Encapsulation

A language construct that facilitates the bundling of data with the methods (or other functions) operating on that data is termed as encapsulation.
     Encapsulation is the word which came from the word "CAPSULE" which to put something in a kind of shell. In OOP we are capsuling our code not in a shell but in "Objects" & "Classes". So it means to hide the information into objects and classes is called Encapsulation.
     Encapsulation hides the implementation details of the object and the only thing that remains externally visible is the interface of the object. (i.e.: the set of all messages the object can respond to).
     Once an object is encapsulated, its implementation details are not immediately accessible any more. Instead they are packaged and are only indirectly accessible via the interface of the object. The only way to access such an encapsulated object is via message passing: one sends a message to the object, and the object itself selects the method by which it will react to the message, determined by functions.
class Loan{
    private int duration;  //private variables examples of encapsulation
    private String loan;
    private Stringborrower;
    private Stringsalary;
   
    //public constructor can break encapsulation instead use factory method
    private Loan(intduration, String loan, String borrower, String salary){
        this.duration = duration;
        this.loan = loan;
        this.borrower = borrower;
        this.salary = salary;
    }
   
    //no argument consustructor omitted here
    
   // create loan can encapsulate loan creation logic
    public Loan createLoan(StringloanType){
  
     //processing based on loan type and than returning loan object
      return loan;
    }
  
}


Read more

Abstract methods

An abstract method is one with only a signature and no implementation body. It is often used to specify that a subclass must provide an implementation of the method. Abstract methods are used to specify interfaces in some computer languages.
Example
The following java code shows an abstract class that needs to be extended:
abstract class Main{ 
abstract int rectangle(int h,int w); //abstract method signature
}

The following subclass extends the main class:
public class Main2 extends Main{
@Override
int rectangle(int h,int w)
{
return h*w;
}
}


Read more

Objects Instantiations

Instantiation of a class literally means creating an instance of a class. This is the process of allocating memory for an object that you can use in your program i.e. you instantiate a class to create an object, a concrete instance of the class. The object is an executable file that you can run in a computer.


Read more

Information Hiding

Information hiding is the primary criteria of system modularization and should be concerned with hiding the critical decisions of OOP designing. i.e. information hiding concept restricts direct exposure of data. Data is accessed indirectly using safe mechanism, methods in case of programming object. 

e.g. Taking bike as an example, we have no access to the piston directly, we can use 'start button' to run the piston.


Read more

Programming Techniques

There are basically four Programming Techniques:
  • Unstructured programming
  • Procedural programming
  • Modular programming
  • Object-oriented programming


Read more

Introduction to OOPS

Object-oriented programming (OOP) is a programming paradigm using "objects" – usually instances of a class – consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction, encapsulation, messaging, modularity, polymorphism, and inheritance. Many modern programming languages now support forms of OOP, at least as an option.


Read more