Lecture 8
Lecture 8
Computing for AI
Lecture – 8
– Procedures typically operate on data items that are separate from the
procedures
But how can a variable hold all data needed to represent a Customer,
Student or Bank Account.
– Using variables ?? E.g.
Student = [first name, last name, modules, degree, address, bank details, etc.]
Object-oriented programming is
centered on creating objects rather Object
than procedures.
Attributes (data)
Object-oriented programming
combines data and behavior
via encapsulation. Object
Data hiding is the ability of an Programming Attributes (data)
Interface typically private to this object
object to hide data from other
objects in the program.
Only an objects methods
should be able to directly
manipulate its attributes.
Other objects are allowed
manipulate an object’s Other
attributes via the object’s objects
methods.
This indirect access is known
as a programming interface.
Methods
(behaviors / procedures)
– A minus (-) sign in front of an attribute (or method) signifies private attribute (or method)
– A plus (+) sign in front of an attribute (or method) signifies a public attribute (or method)
– Note. In UML diagram, no " " prefix should be used for private members.
Class definition: set of statements that define a class’s methods and data
attributes
– Format: begin with class ClassName:
- Convention: Start each word with a capital letter.
Attributes
• None
Methods
• public
• add, subtract, multiply,
divide
• run_calculator
• display_menu
• get_input
– For init (), it should ask for both name and address and initialise the
private parameters.
– Let's save this class into L8_library.py
OOP design
– Object, attributes, methods
Class diagram
– Annotation of attributes, methods, and datatypes
– Annotation of public and private