Learn Object Oriented Concepts for Android Development in Java

Posted by Aria Akachi
6
Aug 28, 2021
409 Views
Image
Learn Object Oriented Concepts for Android : Object-oriented programming (OOP) is a programming language model that allows users to create and organize Java applications on desktops.Writing object-oriented programs involves creating classes, objects and applications which are stand-alone executable programs that use those objects.It simplifies the software development and maintenance by providing some concepts.

A few aspects of Object Oriented development,it can help to make the best of your Android projects,

Objects and Classes

Inheritance
Interface
Encapsulation
Abstraction
Polymorphism

Let’s discuss what are the features of Object Oriented Programming,

A class is a blueprint from which objects are created. It is a logical entity and the class contain. field,methods,constructors,blocks , nested class  and interface.

Syntax
class {  
   field;  
   method;  
}  
Object is an instance of class,it is the physical as well as logical entity whereas class is the logical entity only and objects have state and behaviour entity.
Syntax:
Classname objectname=new classname();

Inheritance
When one object acquires all the properties and behaviours of parent object known as inheritance. It provides code reusability and used to achieve runtime polymorphism.

The extends keyword indicates that you are making a new class that derives from an existing class.

Syntax
class Subclass-name extends Superclass-name  
{  
  //methods and fields  
}  
There are three types of inheritance in java: single, multilevel and hierarchical.

Interfaces
Multiple inheritance achieved through by interface. Interface is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface. An interface does not contain any constructors.
The interface keyword is used to declare an interface/

Syntax
public interface NameOfInterface {
  // Any number of final, static fields
  // Any number of abstract method declarations
}

Encapsulation
Encapsulation is a wrapping code and data together into a single unit. It keeps both safe from outside interference and misuse.If  declare the variables of a class as private.

Syntax
public int getter() {
     return value;
  }
public void setter()  
{
Variables = value;
  }
Abstraction
Abstraction is process of hiding the implementation details and showing only the functionality.
Syntax
public abstract class classname
{
Block of code
}
Polymorphism
Polymorphism is the ability of an object to take on many forms. Java has best support of polymorphism in terms of method overloading and method overriding.

Method overloading
A class have multiple methods by same name but different parameter is known as Method Overloading.  It increases the readability of program and also called as compile time polymorphism.

Method Overriding
When a method in a sub class has same name and type signature as a method in its super class, then the method is known as overridden method.It is also called runtime polymorphism.

Advantages of OOPs

Objects created for Object Oriented Programs can easily be reused in other programs

It is good for defining abstract data types.
It is easy to maintain and modify existing code as new objects can be created with small differences to existing ones.
Object-oriented systems can be easily upgraded from small to large system.

1 people like it
avatar
Comments
avatar
Please sign in to add comment.