Humans are pretty amazing. They have hair, skin, blood, bones, nails and a brain with thoughts which they can turn into action!
There are countless ideas related to the human being!
So, how can we create a model of a human in a computer program?
It depends on what kind of program we are designing.
We need to abstract a model based on the problem we are trying to solve.
For example, a simple computer program needs to store a student's name, age and process his/her gpa.
So, when we abstract a model of a student, what are the essential properties that we need? And what behaviour do we want the student to have?
Often, actions are performed on properties eg graw older will change the data stored in the age property.
OOP is a strategy for managing data in a computer program.
For example, a computer program managing data about Students can design a data model of a Student.
Only essential data is included - so this model is an abstraction.
We can use the model to construct Student objects to help manage student data!
In Java, we can design the model by designing a class.
Once we have design the class, we can use it to construct objects.
bill is a reference variable. It stores the location of the Student object in computer memory, not the object itself.
With this variable, our computer program can communicate with the object!
So, here is a little program demonstrating how we can communicate with the student object:
public static void main(String[] args){
Student bill = new Student("Bill", 18, 3.2);
//access the object's age property
System.out.println("Hello "+bill.age);
if(bill.gpa > 4){
System.out.println("Go to university!");
else{
System.out.println("Get a job!");
}
}
abstract