Friday, February 13, 2015

Summary of object-oriented programming concepts

Object-oriented programming centres around several important concepts, all of which are interconnected, and all of which centre around the concept of the objects themselves, and the ability to perform functions on objects, or to assign objects to variables (such that a variable name contains an object). Objects are things that you can create and assign to a variable name. They include many different types, including float, int, dict, bool, str, list, and many others. Each of these has methods and attributes Classes are specific object types which you can define and write methods and attributes within just like types. You can create an object within a class by making a variable name equal to the class, followed by parentheses enclosing any arguments that the __init__ method of the class takes in other than self - ie, any global variables.  Inheritance is when one class is defined in terms of another in the initial 'class MyClass' statement - which might, in this case, mean the statement would read 'class MyFavouriteClass(MyClass)'. In this case, the class MyFavouriteClass would inherit the attributes and methods of MyClass, if it is initialized in the __init__ method of MyFavourite class like so: 'MyClass.__init__(self, globalvariable1, globalvariable2)'. 

All of these concepts, as mentioned earlier, centre around the object, and how to create and manipulate objects in different - albeit very interconnected - ways. 

No comments:

Post a Comment