As my basic Java journey continues…
Still talking about the java programming language, I got a little introduction to some of its object oriented concepts today. Still talking about the java programming language, I got a little introduction to some of its object oriented concepts today.
These concepts are not constrained to Java alone, but can be used across broad among-st objected oriented programming languages.
I want to mention just a couple of them. Lemme step back a little bit and define object oriented programming.
Object-Oriented Programming is a methodology or paradigm to design a program using classes and objects. It simplifies the software development and maintenance by providing some concepts:
Object Class Inheritance Polymorphism Abstraction Encapsulation
Now an Object is basically just like we relate with them in the real world. They are just things or people that have state and behaves in a certain way. i.e we can categorize a polar bear as an object because it has state like color which is predominantly white. And also it behaves in a certain way which in this case could be that it eats fish.
So in object oriented programming objects must have certain attributes and must be able to perform certain functions. A collection of objects is called Classes.
Now in object oriented programming objects can pass on all or certain parts of their behaviour or state to another object.
So just like a mother and father polar bear begats a child polar bear and passes their polar bear genes to the child bear. Now in normal english terms we would say that the child polar bear inherited certain this from the mother and father polar bear.
The objects we create in object programming languages can also inherit from other objects and this concept is called inheritance.
In computer programming when we want to perform certain tasks which can be repetitive in nature, we write subroutines, functions or methods which we call upon to help us carry out those tasks whenever we want. In java the formal name for this is methods.
Normally we can pass some raw materials
hods that it can use to work and provide us results based on what we gave it.
So I can write a method that prints:
Hello “NAME”
where NAME stands for whatever name I pass into the method.
When one task is performed by different ways i.e. known as polymorphism. In java, we use method overloading and method overriding to achieve polymorphism. What I mean is that I can create a method and depending on the what raw materials I pass the method does different things. It adapts to the attributes you pass into the method to carry out the operations.
In certain scenarios you can call a methods functionality but you don’t know its internal detail. An abstract class shows only important things to the user and hides the internal details for example sending sms, you just type the text and send the message. You don’t know the internal processing about the message delivery. It offer the basic data an ‘object’ should have and/or functions it should be able to do. It concerns on the object’s basic characteristic, what it has and what it can do.
When a collection of methods have just the functionalities and no state. They are called interfaces. They contain only methods. This is useful because it allows a programmer to loosely couple his program.