Object-Oriented Programming is a form of programming where any data type can represented by objects. You can modify these objects by doing certain actions to the object that are particular to this object (in programming terminology, you can call methods defined for a class). Because I don't have experience in a language that is non-OO, unfortunately (or fortunately), OOP has been simply the way I know programming as. Of course, there are both advantages and disadvantages to using OOP as opposed to a different paradigm depending on the situation, so my lack of insight into other styles of programming definitely does not represent my intention to turn a blind eye to the other styles.
From what I've read, there are several features that are unique to OOP.
OOP allows methods to be structured around each data type or concept you want to represent. In this way, it's convenient to call upon these enclosed methods, 'packages', to different parts of your script. It also simplifies the way of making changes to your code, as you could inherit the parts you need from code that you've already written in one object to another, and make then the necessary changes or additions that pertains to this new object you're presenting. OOP allows developers and users to use code in a way that makes sense intuitively by abstracting the exact implementation of the methods. So if you want to 'pet a cat', for example, you don't need to know the details of how exactly which muscle will be used in generating which kind of movement to pet the cat, you just pet the cat. cat = Cat.pet()
In general, OOP allows for a very 'human' way to tackle a problem in programming.
Recursion is a technique for solving a problem by breaking it up into smaller and smaller problems of the same nature. The solutions of these smaller problems then piece together in the end to bring about the final solution. In Python, you use recursion by calling, say, function_a() within itself, modifying the parameter by a little so to chop up the problem every time the function recurses until you get to a base case. Once a value is derived at the smallest part of the problem, it then gets substituted back into every level the function has been called until the problem is finally solved at large.
Although recursion is not always the preferred way to solve a problem (due to the recursive nature of recursion, if base cases are not handled correctly, it could result in some unwanted results), recursion is still very powerful in that it allows one to reach a solution to a complex problem in just a couple lines of code.
No comments:
Post a Comment