In CSC108, we did if statements, loops, defining functions, calling a function, lists, dictionary etc. Proceeding to the CSC148 lecture, we begin with
Object-Oriented Programming (OOP). The programming language we use is Python which is an OOP language. This give me a deeper understanding of Python.
Object-Oriented Programming
OOP uses the concept of
objects.
Attributes are to describe the objects.
Methods are functions inside an object where you pass an attribute. The basic elements in Python are like
str, dict, int, different functions etc, which are all examples of objects. An object includes data and functions. Relationships can be created in OOP between one object and another. One advantage of OOP is that the defined objects and functions could correspond to the real-world.
Designing a class
After an object is identified, we could design a
class. In python, we can create our own defined class. In the lecture, our professor suggested finding the most important noun which could be a name for a class, the important attributes and operations of the noun as the methods. In class definitions, usually there will be function definitions which starts with
def followed by some arguments and methods.
The form of class definition is as follows:
class ClassName(object):
""" A class example"""
def function(self):
pass
This is the basics of designing a class, in the coming weeks, there will be more implementations of class design and hopefully with these basics I could design better classes.