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

U102_Activity_OOP

The document covers the fundamentals of object-oriented programming (OOP), emphasizing concepts such as classes, objects, attributes, methods, abstraction, and encapsulation. It provides examples of classes like BankAccount and Student, detailing their properties and methods, and includes activities for designing systems like a library and an animal management system. The document aims to enhance understanding of OOP principles and encourage practical application through design challenges.

Uploaded by

mithranv2008
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 views10 pages

U102_Activity_OOP

The document covers the fundamentals of object-oriented programming (OOP), emphasizing concepts such as classes, objects, attributes, methods, abstraction, and encapsulation. It provides examples of classes like BankAccount and Student, detailing their properties and methods, and includes activities for designing systems like a library and an animal management system. The document aims to enhance understanding of OOP principles and encourage practical application through design challenges.

Uploaded by

mithranv2008
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/ 10

Applied

Computing
Unit 1 Area of Study 2
Object-oriented Programming

© DLTV (Digital Learning and Teaching Victoria) 20


24
Types of programming
• Top-down programming approach includes a call to
routines, sub-routines or functions
• Object-oriented programming includes capturing
properties and functionality into objects (just like real-
life)

© DLTV (Digital Learning and Teaching Victoria) 20


24
Objects
• An object has attributes: properties and functionality
(methods)
• An object is created using a class. Think of a class as a
template for objects
• When an object is created using a class, it is an instance
of the class. The terms object and instance can be used
interchangeably
• For example, a class fan can have:
• Properties – colour, blade_length, num_blades, speed
• Methods – can be turned on/off, apply spin speed
© DLTV (Digital Learning and Teaching Victoria) 20
24
Terminolo Class
gy
Object/
Instance

Attributes

Properties Methods

© DLTV (Digital Learning and Teaching Victoria) 20


24
OOP Concepts: Abstraction
• In OOP, abstraction allows the programmer to hide complex
details from the user.
• In a real-life example, a car has an accelerator and a brake that
drivers can use. The drivers know how to use both these
functions but may not necessarily know the internal mechanisms
that makes them work.
• The same can be said of objects in OOP. Programmers can create
objects and hide the complex details while showing the user only
the required data and functionality.
• This type of programming allows for well-organised code and
increases efficiency as it encourages code re-use.

© DLTV (Digital Learning and Teaching Victoria) 20


24
OOP Concepts: Encapsulation
• In OOP, encapsulation is a way of controlling access to the object
data and methods.
• This allows programmers to protect data from accidental or
intentional modification.
• Programmers can make some of the class public and some
private.
• For example, for the class BankAccount, the property balance
may be set to private and methods such as withdraw() and
deposit() can be set to public.

© DLTV (Digital Learning and Teaching Victoria) 20


24
Examples
Class: BankAccount
Properties Methods Instance
accountName findBalance() acc1 = BankAccount()
accountType withdraw() acc1.accountName =
deposit “Barry”
acc1.accountType =
“Savings”
acct1.findBalance()
acct1.withdraw(50)
Class: Student acct1.deposit(120)
Properties Methods Instance

Name enrolCourse() student1 = Student()


studentID dropCourse() student1.Name = “Sarah”
enrolledCourse printSchedule() student1.studentID =
40404040
student1.enrolledCourse =
“Bachelor of Computing”
student1.printSchedule()
© DLTV (Digital Learning and Teaching Victoria) 20
24
Activity 1
Design a library system. It should include two classes: Book and Member. A book by default is
available to borrow. Basic details are stored about the book. A book can be borrowed and returned,
both of which changes its availability. Basic details are stored about the member. A member can
borrow a book, return a book, rate a book and see what books they have borrowed.
Complete the tables below. Suggest some properties, methods and what an instance could look like.
Hint: use the tables on the previous slide to help you).

Class: Book
Properties Methods Instance

Class: Member
Properties Methods Instance

© DLTV (Digital Learning and Teaching Victoria) 20


24
Activity 2
Design an animal management system for a zoo. It should include two classes: Animal and Zookeeper.
Some basic details are stored about the animal. The animal is fed, its health is checked and on occasion,
the animal is moved to a different habitat at the zoo. Some basic details are stored for a zookeeper. The
zookeeper is assigned some animals to care for, and feeds the animals assigned to them.
Complete the tables below. Suggest some properties, methods and what an instance could look like.

Class: Animal
Properties Methods Instance

Class: Zookeeper
Properties Methods Instance

© DLTV (Digital Learning and Teaching Victoria) 20


24
Challenge!

• Take activity 1 or 2 and develop pseudocode or code for


the two classes.

© DLTV (Digital Learning and Teaching Victoria) 20


24

You might also like