OPS435 Python Lab 7
LAB OBJECTIVES
- Object-oriented programming is one level of complexity higher than simply structured programming as you've experienced in languages such as Bash or C. In this second lab on objects we're going to look at slightly more complex issues that come up when using them.
PYTHON REFERENCE
- In previous labs, you have been advised to make notes and use online references. This also relates to learning about objected oriented programming to help becoming "overwhelmed" with the volume of information in this lab.
- Below is a table with links to useful online Python reference sites (by category). You may find these references useful when performing assignments and labs.
Category | Resource Link |
|
INVESTIGATION 1: Classes and objects
In the last lab we created a class named Student and a couple of objects of type Student which were named student1 and student2. Let's spend some more time on that distinction.
A class is a type, a description of a thing, the definition of what it should look like. An object is an instance of a class, an individual described by a class, a specific thing with properties defined by a class. Here are some examples of what might be types and what might be objects of those types:
Class | Objects of that class |
IPAddress | 192.168.1.3, 192.168.1.10, 10.0.0.50, 142.204.1.2 |
Person | Andrew Oatley-Willis, Murray Saul, Andrew Smith |
BMWModel | BMW2Series, BMW3Series, BMW4Series, BMWXSeries, BMWMSeries, BMWiSeries |
Car | Andrew's silver Civic with VIN 1234567890, John's blue Subaru with VIN 0987654321, Evan's BWMMSeries with VIN 4567981230 |
The exact definition of the type and what you would expect to store in objects of that type is up to you - the programmer. You want to design your classes so that you can manage data in your application as easily as possible.
Note that inside a program typically a class name starts with a capital letter and object names, as typical variable names, start with a lowercase letter.
LAB 7 SIGN-OFF (SHOW INSTRUCTOR)
- Have Ready to Show Your Instructor:
- ✓ Output of:
./CheckLab7.py -f -v
- ✓ Output of:
cat lab7a.py
- ✓ Output of: