Challenge

Project

The main principles of Object Oriented Programming are:-

  • CLASSES
  • OBJECTS
  • ENCAPSULATION
  • INHERITANCE
  • ABSTRACTION
  • POLYMORPHISM

In my Object Oriented Programming , the main factor is to make your code modular and having different classes which have different functions and methods which can be called to achieve that function. This makes the code more readable and understandable for others . Also we can use pacages to categories all the classes for better use. In my calculator code all those functions , either mathematical or used for other purpose like checkChoice , to check the user choice is valid or not , ane in different classes and also all the mathematical functions are in well defined packages like all arithmetic operations , i.e. + , - , x , / , are in ArithmeticOperators package. Similarly , all trigonometric functions like sin , cos , tan , isin , icos etc. are in same package named TrigonometricOperations and others operations are also in there respective packages.

Class methods can be used by creating objects of that class. Objects are instance of a class and have all the properties written in the class. Memory is only assigned when we create objects of classes. So any class can be used using there respective objects. For example, Scanner class is imported for taking input but first we create an object by syntax : Scanner sc = new Scanner(System.in) , here sc is the object and its different properties can be used by adding more syntax like , for choice variable which requires int valur , we use choice = sc.nextInt().

Encapsulation is a mechanism of wrapping the the data or the vaariable , and the code acting on the data i.e. methods, together in a single unit. In this , the variable of a class will be hidden from other classes. This concept is also called Data Hiding. It gives code security and a realy important aspect of Object Oriented Programming . in my calculator code, every operators package has a Variable class which takes the input and on the basis of that , other operator classes do there work. The variables used in those operations ane encapsulated. This is done by first using private keyword to the variables (var1 , var2) and then created there getters and setters. Also all the inputs given by the user is checked in variable class. So that if unwanted input is given by user, then the programme don't terminate.

Inheritance is an important aspect of Object Oriented Programming . It is a mechanism that allows to inherit features of parent class and give to child class. It simply means the sub class we create will have all the properties of the parent class. This can be achieved easily by adding extends <parent class name> after declaring child class. In my code the Variable class in all of the Operation Packages are parent classes because all the child classes i.e. all mathematical function classes in a package have common type of input. For e.g. all Arithmetic operations i.e. + , - , x , / , have two inputs on which operation is done.Similarly done for rest of the operation packages.

Abstraction is the process of hiding perticular details and only to show essential information to user. Adding abstract word means , it's just an idea and need to be implemented further. Since multi class inheritance is not allowed in java , thus using abstract method we can achieve that. It is achieved by using either abstract class or interfaces.

It's also a realy key aspect of Object Oriented Programming . It has a mechanism so that if we want to restrict some some properties of some inherited and abstract classes to child class we can do this or we can perform a single action in different ways.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.