2015年2月25日星期三

Summary of Object-Oriented Programming Concepts(Week 5)

  It's my first time to know object-oriented programming(also known as OOP) concepts. We already have used the knowledge about this while doing assignment 1.

  "In object-oriented programming, computer programs are designed by making them out of objects that interact with one another." said by two computer scientists. In CSC108, most of the time, we were using procedural programming, which mostly focuses on writing functions. However, as these two scientists concluded, OOP mainly concentrate on both data and functions, which means class (including superclass and subclass), inheritance, interface and methods are of vital importance.

  According to the sentence mentioned before, the very first thing we need to know is "object". Obviously, "object" is the key to understand OOP. Object has its won properties and state, just like every object in our daily life. Also, object could expose its behavior through methods.

  Secondly, what is "class". Class is the blue print of a program. It help us organize our thoughts and makes your codes readable for others. It's like building a house, class is the frame. After building the frame, we need to put things in the frame, which are our functions. 

  Thirdly, speaking of class, one of the most important thing is the relationship between superclass and subclass. They are like parents and children respectively. Children could inherit all the characteristics of parents,which is known as inheritance, and of course, develop their own uniqueness. In my opinion, superclass-and-subclass relationship is one of the ways that make interaction between objects possible.

  The last, "interface" and "method". An interface is a contract between a class and the outside world. Objects define their interaction with the outside world through the methods that they expose. We've already learnt four main methods which are the most common form -- "__init__", "__str__", "__repr__" and "__eq__". Each of them has its own unique role. "__init__" is used for initializing, "__str__" is for printing, "__repr__" is for evaluation and "__eq__" is for comparison. All of them make the class more formal about the behavior that it acts.


  There are a lots of things we need to learn about OOP and I believe it's the main target of CSC148. Although it's kind of difficult at first, I still find it interesting and I'm looking forward to learn more about it.

没有评论:

发表评论