2013年10月13日星期日

[WEEK V] Object-Oriented Programming and Recursion

    So, for this week we are asked to write two paragraphs about object-oriented programming and recursion, also explain its concept and usefulness.

Object-Oriented Programming

    I looked up on the internet about its information. Generally, object-oriented programming, which can be represented as OOP, is a programming model that 'objects' have data field and associated functions known as 'methods'. There are lots of OOP languages such as Python, Java and C++. An example for the OOP languages is they use 'class', which can be considered as a union of a certain type of information. They also use 'objects' and 'methods'. 'Objects' can be considered as a certain object belong or related to the defined class and 'methods' are under the classes and can be considered as the actions toward the defined objects by programmers. For instance, in Python, we could define a class 'Laptop' and an object under the class 'Laptop', 'Vaio', which means 'Vaio' is a 'Laptop'. In addition, we want to turn on the 'Vaio', so we define a method called 'Turn_on'. As the result, when we type  Vaio = Laptop/ Vaio.Turn_on() in the Python Shell, it means 'Turn on the laptop called Vaio'.

    It has valuable usefulness because programmers can assign value and data to any objects, and any defined objects can be used to process data and transfer data to other defined objects. It greatly enhanced the programs flexibility, compatibility and makes the program much more simple to maintain. This kind of language is widely used by software engineers, because it is easier to study and analyze the code for novices, also easier to design and maintain the program for experienced programmers compared to non-OOP language programs.

Recursion

    Recursion is a method of programming that divide a problem into two parts, which are basic cases and sub-problems. Basic case is 0 or empty list/string for the most of time and for the sub-problems, the function calls itself to repeat computing until the basic case occurs.  A failed recursion code can cause an infinite loop.

    Recursion is very useful as well since it eliminates the unnecessary code and increase the its efficiency. A complicated task can be easily done by the recursion by break it down to two parts, and for more complicated problems we can break down sub-problems into sub-sub-problems and so on to solve them nice and clean.

没有评论:

发表评论