Java

1 minute read

What is Object Oritentated Programming?

OOP is a programming paradigm (much like functional programming) where everything is considered an object. As an example a person can be considered an object. Objects can have attributes such as a person’s first name, last name, or their date of birth.

Objects can be shown graphically using tables like so

Person  
  Firstname: String
  Lastname: String
  Date of birth: String
  new Person (Firstname: “Brandon”, Lastname: “Skerritt”, Date of birth: “3rd of May 1997”)

In this table we can see that an object exists called Person and it has 3 attributes, first name, last name, or their date of birth. We write how to call this object at the bottom of the table.

Each class can have methods (functions) which allow them to calculate the attributes they have.

Data Encapsulation

Object’s data cannot be accessed directly or modified directly. If you want to get person’s first name, you need to ask it for it. In this case

Brandon = New Person(Firstname: "Brandon", Lastname: "Skerritt", Date of birth: "3rd of May 1997")
Brandon.Firstname = "Brandon"
Brandon.Lastname = "Skerritt"

Inheritance

Objects can inherit from other objects. If you have an employee object, all employees are people, so therefore employees can inherit from people.

Person  
  Firstname: String
  Lastname: String
  Date of birth: String
  new Person (Firstname: “Brandon”, Lastname: “Skerritt”, Date of birth: “3rd of May 1997”)
Employee  
  Employee ID: Number

In this diagram, Employee inherits Firstname, Lastname and Date of birth from the Person object.

if your method does not return any data use the void wqord

UML

  • is for public
  • is private # for protected

Categories:

Updated: