(Use this for Week #7)
At first, I wasn't sure what to write about. Object-orienting probably means to refer to another object, right? This is probably related to programming as well... Maybe classes?
Looking back at my multiple pages of lecture notes that are based on classes, inheritance, and recursion, I suppose this is what "object-oriented programming concepts" are. These concepts enable objects to refer to other objects such as a child's class would inherit attributes from its parent class, also known as the super class. Maybe this would make sense:
class Child (Parent):
""" Optional docstring about the child, or at least I like to think it's optional. This child has been
born from its parent class, Parent. """
Let's say the Parent class had, for example, blue eyes. (Obviously a class doesn't have blue eyes but this is how I see it.)
class Parent:
""" Optional docstring about the Parent. """
def __init__(self):
pass # this method isn't the point I'm trying to prove, so I apologize for my laziness
def eye_colour(self):
print('Parent has blue eyes')
But the possibility of the Child having blue eyes is much lower. A biology student could probably prove this, but unfortunately, I am not one.
class Child (Parent):
""" Optional docstring about the child, or at least I like to think it's optional. This child has been
born from its parent class, Parent. """
def __init__(self):
pass
def eye_colour(self):
print('Child has brown eyes')
As you can see, the Child class' method eye_colour overrides the Parent class' code. In this example, the child is the subclass and the parent is the superclass.
Although a child inherits features from a parent, it's possible that its DNA would differ from the parent's, thus replacing the parent's features with the child's. From my point of view, object-oriented programming concepts is the way objects interact with each other, just as a parent and child relationship.
No comments:
Post a Comment