Abstracting

 

Abstracting means to ignore or hide everything except essential data that we require for the given problem or situation.

The London tube map is a great example of an abstraction. We don't need info about shops, house addresses or precise directions. We just need station names linked together.

Non-essential information is ignored as we develop an abstraction.

Creating Abstractions

modeling the real world with computers programs

Modeling the real world with computer programs

 

man

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?

Abstract the model!

Often, actions are performed on properties eg graw older will change the data stored in the age property.


What about OOP?

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.

Luv ♥ hi! Whassup?! Coffee? bill Student(String, int, double) String getName() int getAge() void setGPA(double newGPA) name "Bill" length() substring(int) equals() age 18 3.2 gpa

reference variables

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!");

}

}

Tags

abstract


Welcome to the hard stuff

OOP may be very unfamiliar to you. This will make it seem very difficult.

Experience will help you.

Struggling will help you.

Asking questions will help you.

Developing your English skills will help you!

Understanding the Data Type you are working with will help you - eg Student, Elephant[], ArrayList Hammer, String...