Object oriented programming is a must known programming style in order
to be a better programmer.
Many people recognize this term by thinking of class and subclass, and
that is correct.
Object oriented programming is a programming style where programmer initializes
data structure, data type and functions that can be applied to data structure
while coding. (For detailed version of this go to the website:
http://www.webopedia.com/TERM/O/object_oriented_programming_OOP.html
OR the wikipedia site: http://en.wikipedia.org/wiki/Object-oriented_programming)
The benefit of object-oriented programming is that there is no need to
create new modules every time when new types of objects are added. If
certain objects share same functions or methods, it can be stored in superclass
and programmers can use subclass to specify certain functions or methods that
make them to be used in their unique ways.
Object-oriented programming is used big in languages Java, C++, Python,
and more.
In my opinion, object-oriented programming makes coding much convenient
and more organized.
There is no need to create classes every time I need new objects even
though some aspects or functions of them can be shared.
Relating to my course that I'm taking (CSC148), here is an example of
convenience of using object-oriented programming:
class Student:
def __init__(self, age, number):
“””
“””
self.age = age
self.number = number
def get_age(self):
“””
“””
return self.age
def get_number(self):
“””
“””
return self.number
class Jeff(Student):
def __init__(self, age, number):
“””
“””
Student.__init__(age, number)
class Jae(Student):
def __init__(self, age, number):
“””
“””
Student.__init__(age, number)
Not using OOP:
class Jeff:
def __init__(self, age, number):
“””
“””
self.age = age
self.number = number
def get_age(self):
“””
“””
return self.age
def get_number(self):
“””
“””
return self.number
class Jae:
def __init__(self, age, number):
“””
“””
self.age = age
self.number = number
def get_age(self):
“””
“””
return self.age
def get_number(self):
“””
“””
return self.number
As you can see, the more function
subclasses share, the handier OOP comes in.
Example above only shares 2 functions so it is hard to notice but still
you can tell non-OOP ones have longer code lines. Moreover, non-OOP code lines increases
gradually compare to OOP code lines (non-OOP needs to rewrite functions every time
in need of new class).
Therefore, a programmer who wishes to be a
better coder and his/her program to run faster and better, he/she will have to
be fluent in Object Oriented Programming.
No comments:
Post a Comment