Objects are Instances of a Class
Classes and Objects
Classes & Encapsulation
A Class is a template of an object. It represents data.
Encapsulation: Class wraps properties and methods together
Objects are Instances of a Class
Object Oriented Programming
object.attributeexpression
Classes Serve as instance factories. If classes are cookie-cutter.
Instances If classes are cookie cutter, Instances are cookies.
class C2: ... # Make class objects (ovals)
class C3: ...
class C1(C2, C3): ... # Linked to superclasses
I1 = C1() # Make instance objects (rectangles)
I2 = C1() # Linked to their classes
classes are really just packages of functions
classes support code reuse and customization of software
Coding Constructors
Define a constructor with the __init__ constructor method
Assign the 1st argument to self in the __init__ constructor method.
Let’s add one to our class:
Next, assign each self.attribute to each argument For Eg. self.name = name
No Comments