In: Computer Science
Create a new post where you provide guidance on Java installation and discuss the concepts and features of the object-oriented design principles.
Since it is question and answer portal, so java installation and object oriented designs and principles are explained below:-
JAVA INSTALLATION
OBJECT ORIENTED DESIGN
Object oriented design is used to overcome drawbacks of procedural programming approach. Before this approach, all programs and principles were not close to real world applications.
In this approach, we define a state and its behaviour. Taking an example of real world, mobile phones is a state and it has different behaviours. Customers are only interested with its features, applications and handy look. They are not interested with the working of its internal softwares or hardwares used inside it. So in mobile phones, customers has access to few functionalities or behaviours, rest others are hidden from them.
In similar manner, we can use object oriented programming to achieve this task easily. State i.e. mobile phone is taken as a class which has different objects i.e. mobile phone which a particular customer is using. Now class will have different behaviours i.e. data attributes and methods. Now each instance of this class can only access only few behvaiours from all behaviours defined in the class.
Different principles of object oriented programming is as follows:-
ENCAPSULATION :-
It is a mechanism of wrapping data attributes and methods in a class. Each class can have some variables known as data attributes and functions known as methods to provide all relevant behaviours for that class.
Example :-
class MobilePhones {
private :
int number;
char brand[100];
char processor[100];
char storage[100];
public :
void powerON();
void powerOFF();
void openApp(char appName[100]);
void install(char appName[100]);
void openApp(char appName[100]);
}
INHERITANCE:-
It is a mechanism where one class can inherit few properties from a class and can change its implementation as per its own requirement. For Example, if car is a class then it has the functionality that every car will have 4 wheels, will drive and have sitting space. But each model of car will have different appearance, mileage, price etc. Still those different models will have all functionalities of car. So these all models will inherit all properties from parent class and will then change if required or will add there own new functionalities or behaviour.
class Parent {
public :
void fun();
}
// Child class that is inheriting parent class
class Child : public Parent {
}
ABSTRACTION:-
It is a mechanism of showing only essential or relevant details to user and ignoring the explanation or irrelevant details from them. It is used to reduce the complexity of program. It helps to provide only the behaviour of a particular state and separates its explanation so that code is understoodable and is less complex.
In java, Abstract Classes are used to implement this principle. In abstract classes, it can have abstract methods. Abstract methods only has the function declaration and defination is provided by child classes i.e. which has inherited this class. So its explanation is provided in other class and abstract class will only have name of all relevant behaviours required.
DATA HIDING :-
It means to hide data from some part of component. It is used to achieve encapsulation i.e. private data is not accessible outside class or objects of that class. It is used to achieve the functionality that few behaviour is hidden and few is only accessible to user.
POLYMORPHISM :-
It is the mechanism to process same functionality or task in different ways as per its usage. For Example:- sum method is used to add 2 numbers and also to add 3 number. So the name of functionality is same i.e. sum but is performing different operations.
class adding {
public :
void sum(int a, int b) {
return a+b;
}
void sum(int a, int b, int c) {
return a+b+c;
}
}