top of page
Writer's picturejesskesson

Object Oriented Programming

Updated: Jun 10, 2019

Today we learned about object oriented programming, and different ways we can do this. Object oriented programming is where objects are programmed with methods and attributes. A method would be that an object can jump, and an attribute would be how high an object can jump.


Objects are a collection of data (variables) and methods (functions), which can be affects and changed in different ways.

This code is all about a class with two objects in it. They are both "Birds" called Blu and Woo, who are aged 10 and 15 respectively. This does nothing for what the code does. However, it is part of the attributes these objects have.


I had a go at changing the ages and names of the objects, to make it more entertaining.


The first thing we learned about was classes, which are blueprints of objects.

In this code, there is one class, called 'Parrot', and in class Parrot there is one object. The object is coded to recognise it's attributes and methods, name, and age.

It's method is called sing, and to dance.

At the bottom of the code, it prints out it's attributes, in a string.


This code is using Inheritance as a factor. A parent class is the original class, per say, and the child class has attributes from it. So, class penguin has some attributes from class bird, the parent class.


This piece of code is about Encapsulation. Encapsulated code is code that isn't able to be manipulated. Like statistics in a fighting game, it would be unfair if someone went and changed it.


In this code what's happening is the maxprice attribute is private, and cannot be edited. Thus meaning the prices of computers can't be changed.


the final part of object oriented programming we learned was polymorphism, which means that two objects can have the same method, yet different attributes to the methods.


The two classes in the code above have the same method, which is flying, yet they have different attributes. Class Parrot's fly method is an attribute they are strong in, yet swimming is not. For Class Penguin, it's the opposite. However, this code is only printing the methods and attributes in a string of text.

2 views0 comments

Recent Posts

See All

Comments


bottom of page