0% found this document useful (0 votes)
4 views12 pages

OOP 3 Student

The document provides an overview of Object-Oriented Programming (OOP) terminology, including definitions of key concepts such as classes, objects, methods, and attributes. It outlines a practical task for creating a Monster class for a game, detailing steps for defining the class, implementing attributes and methods, and using getters and setters. The document also includes a class diagram and instructions for planning and testing the class in a programming environment.

Uploaded by

reg22203087
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views12 pages

OOP 3 Student

The document provides an overview of Object-Oriented Programming (OOP) terminology, including definitions of key concepts such as classes, objects, methods, and attributes. It outlines a practical task for creating a Monster class for a game, detailing steps for defining the class, implementing attributes and methods, and using getters and setters. The document also includes a class diagram and instructions for planning and testing the class in a programming environment.

Uploaded by

reg22203087
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

OBJECT ORIENTED PROGRAMMING

Starter activity

OOP terminology – Match the term to the definition

A special method used to create a


Constructnew object from a class

or
The associated actions of an object.
Method

AttributThe individual properties of an object.

e
Every new object created from the
Instance
same blueprint.
2
Terminology

Terminology

 OO  OOP
 Object Orientation:  Object Oriented Programming:
“Looking at systems by “A method of programming
classifying them into real which classifies real world
world objects” objects into classes and
encapsulates those objects
attributes and behaviours.”
Terminology

Terminology

 Class  Object
 A type definition of an  An instance of a class
object
Terminology

Terminology

 Instantiation  Method
 The process of creating an  “A program routine contained within
actual named instance of a an object designed to perform a
particular task on the data within the
class. The instantiated object. A method can broadly be
named copy of the class in thought of as a procedure / function
an object of that class. from more traditional procedural
programming languages.”
Starter activity

Planning a new class

Congratulations! You have been selected as a


game programmer for the upcoming puzzle
game Monster Quest.

Your first job is to create a program for


managing the monsters in the game, you
need to use object-oriented programming to
do it.

6
Class Diagrams

Class Diagram

This is a UML class diagram.


Pet
It is part of Unified Modelling Language (UML) which is used to design
software.
name: string
Use this to help you plan your program.
species: string
description: string

get_name()
get_species()  Attributes and their data types.
get_description()  Also called instance variables
set_name(self,name)

 Methods and their parameters.


Class Diagrams

Planning your Monster

 Each monster must have a name,


Monster health points and a line of dialogue.

-monstername: string  Each monster must be able to take


-monsterhealth: integer damage and speak to the player.
-monstertalk: string
-monsterdmg: integer  What attributes will you need to add
-get_monstername() to your monster to meet the criteria?
-get_monsterhealth()  Attributes go in the top box.
-get_monsterdmg  What actions/methods does your
-get_monstertalk()
monster class need to be able to use?
 Methods go in the bottom box.
Monster.

Create the class and Constructor

Task . Create the Monster class


Monster
A. Create a new file in your project called monster.py
-class monster
B. Define your new class at the top. -take_dmg(self, dmg)
-speak(self)
a. Use the Pet class to see how it should look

C. Create a constructor

a. Make sure to include all of the attributes in the class

diagram.
Task
Create the getters and setters
1.Add getters and setters to your class
Make sure you have one for each of the attributes in the Monster class
Tas
Test your new class
2.Create a new file called main.py
3.Import the class at the top of the new file, like this…
1 from monster import Monster

Create a Monster object


Use the constructor
Choose a name, health point total and a line of dialogue for the Monster

More Tasks
Use the new getters and setter to do the following:
4.Print the name of the Monster
5.Print the line of dialogue
6.Change the health points to another number
7.Print the new health point total.
Task

Create the take_damage and speak methods

Take damage:

● Take the damage parameter away from health attribute

● Print the new health total

Speak

● Print who is speaking (name)

● Print the line of speech.


Summary

Next lesson

In this lesson, we… Next lesson, we will…

Designed a class Learn about the principle of inheritance

Created a class from scratch Extend our Monster game to add new
subclasses.
Accessed and modified attributes on an
object using getters and setters

Defined and used methods from a class

1
2

You might also like