IAT167-Week 5 Lecture 2.docx

27 views2 pages

For unlimited access to Class Notes, a Class+ subscription is required.

Week 5 Lecture 2
OOP Concepts
Encapsulation
Inheritance
Class Interfaces
Polymorphism
Encapsulation
The ability of an object to be a container for properties (data) and methods
The ability of an object to hide and restrict access to internal properties and methods
Accessor functions allow class consumers to read internal variables
Mutator functions allow class consumers to change internal variables
Example:
Object {
public var x:int;
public var y:int;
public function show();
}
Access Control
internal (default) - Visible to references inside the same package.
private - Visible to references in the same class.
protected - Visible to references in the same class and derived classes.
public - Visible to references everywhere.
static - Specifies that a property belongs to the class, as opposed to instances of the class.
Get / Set
Access a class variable via functions but as if directly
Allows you to put conditions on when getting and setting is allowed
Inheritance
The capability of a class to use the properties and methods of another class (its superclass)
while adding its own functionality (the subclass)
Example
class Wheel{
var hub;
var spokes;
var rim;
function roll();
}
class RearWheel extends Wheel {
var gears; function pedal();
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+
$10 USD/m
Billed $120 USD annually
Homework Help
Class Notes
Textbook Notes
40 Verified Answers
Study Guides
1 Booster Class
Class+
$8 USD/m
Billed $96 USD annually
Homework Help
Class Notes
Textbook Notes
30 Verified Answers
Study Guides
1 Booster Class