We were asked to go to Poundland with £10 to spend on getting items that would help us teach a Computing lesson. My colleague and I chose to teach the fundementals of OOP and objects usin a selection of toys that we bought – eg some rubber balls, plastic cars, dinosaurs etc.

Here is the outline of teh mini lessonw e gave to our peers:

 

OOP – Classes, Sub Classes, Inheritance, Properties & Methods

STARTER Get toys out on the table

“What are all these items?” Answer – hopefully “Toys”

These items are all part of the Class of “Toys”

They have similar properties – you can play with them – what else??

What groups can you see here? Get toys and group them by type – eg cars, animals, soft toys

These can be called sub classes which inherit characteristics from the parent class

Pick up two cars.

These are both in the class “Car”

Eg Yellow car and blue car

“These are instances of Car – they are objects or the class Car”

We could name them “YellowCar” and “BlueCar” – or Car1 and Car2

Properties

Each car has properties – pieces of information about each car – eg

  • Color
  • Size
  • Number of Doors etc

Can you think of any others?

Properties are essentially static – you can’t easily change them – just read the value

Can you think of some properties of any of the other groups of classes?

E.g. Dinosaurs –

  • Size
  • Number of legs
  • Has it got spikes?

 

Challenge can you think of a property for the Toys superclass? (eg suitable age, material made of, needs batteries?)

Properties of the parent class are automatically “inherited” by the sub classes

So if the Toy parent class has a property of “suitable age” then the Cars classes will inherit it, so it will also have that property.

OOP-hierarchy

Methods

Methods are the actions that an object can perform

Eg A car can drive or stop

A Dinosaur can attack

A ball can bounce or be thrown