In CSC108, I have done most tasks by writing several functions separately in Python, though there are some connections between these functions (i.e this function calls another). I have already learned the concept of class in CSC108 but seldom used it.
Object-oriented programming is quite useful, because it is a collection of all the similar objects and methods. In the first lecture, I learned the class Point. The methods avoids duplicate code and make it more efficient.
Classed can call each other and inherited from one or more classes. It dramatically enhances the efficient. For example, in last week's exercise, the class "Toy" calls the class "Play"'s methods, so it is not necessary to write another similar method in "Toy".
Class inheritance is a powerful tool to deal with certain problems. In CSC108, we have known unittest in Python. It creates a new class which is the subclass of the built-in class unittest.TestCase to test the module. So we do not need to write some complex code to deal with the test problems. Class inheritance allows new classes to add new methods, adjust, and override methods in derived class. Built-in functions isinstance() and issubclass() which return Boolean values allows us to check the type and inheritance. Last week, we wrote a class "Stack" and this week we created its subclass "IntStack". Generally, "IntStack" inherited the methods from "Stack" , like __init__, push, pop, is_empty. But it makes some changes, in "push" method, we allows integer only, so in the method "push", we used a "if statement". When the argument is not integer, it raises an exception which is something new for me. And when the argument is exactly inter, we just run the method in "Stack", quite simple and easy. Also, we optimized the method "pop", raising an exception we want when the stack is already empty.
Right now, many software are written in object-oriented language and it is a popular kind of language. I am looking forward to learn more about object-oriented programming.
Nice explanation! OOP is powerful indeed!
ReplyDeleteAgree!
Deleteremind me how it compares to Pascal... a language less than useless...
ReplyDeleteless than useless hahaha
DeleteI didn't recognize that unittest also uses inheritance until I read your slog!
ReplyDeletewe did learn lots of stuff in CSC108!
also, I think your interpretation of OPP is very good! I was not like this when I was writing my OPP slog. I was very confused at the beginning of class, and I just can't understand what other students are writing about.
Now after a whole term of OPP, I can see why you stated that many softwares are written object-orientated language. OPP is powerful indeed!
Agree! OOP is so helpful.
Delete