1. Choose your own category
2. Look for subcategories with similarities or shared attributes (atleast 3 subcategories)
3. Map inheritance on paper, list properties and methods
4. Define PHP classes
5. Inherit, extend, and override properties and methods
6. Create instances to test
Category Ideas: Animals, Clothing, Foods, Furniture, Musical Instruments.
class Person:
def __init__(self,name,sex,age):
self.name = name
self.age = age
self.sex = sex
class Cat:
def __init__(self,name,sex,age):
self.name = name
self.age = age
self.sex = sex
class Dog:
def __init__(self,name,sex,age):
self.name = name
self.age = age
self.sex = sex
# Inherited usage:
class Aniaml(object):
def __init__(self,name,sex,age):
self.name = name
self.age = age
self.sex = sex
class Person(Aniaml):
pass
class Cat(Aniaml):
pass
class Dog(Aniaml):
pass
Comments
Leave a comment