Sunday, 1 March 2015

Week 7

Object-Oriented Programming Summary

     This week I will be providing my summary of Object-Oriented Programming. One of the things I have learned throughout my experience in computer programming is the necessity of defining the semantics used in order to develop a thorough understanding of the concepts. This was often skipped over throughout the introduction to computer programming and continues to be assumed knowledge within computer science lectures and course material. However, misunderstanding the language used in programming can result in gaps within the learning experience which easily inhibits one's overall ability to grasp how the computer operates and what is happening behind the code.

     Within the programming world, objects are defined as self-contained functions or variables such as classes, lists and dictionaries. In turn, functions describe what you can do with the class, without storing any information, while variables are used within the functions to store information and attributes (variables inside a class). If a function is required to affect the variables contained within it and change their value it can not do this. Therefore, what is required is a way to group closely related functions and variables so that they have easy access to one another and can interact to fill in missing pieces of information. One way to do this is by implementing a class. Classes are data structures that hold methods (pieces of code associated with objects or instances of a class) and code to process data in the same spot which describes how to make something or acts as a blueprint for the design. A class can also be referred to as the implementation of a type which generally represents a noun (person, place or thing aka an object). For example, when a group of "objects" share a common design but have some changed properties (aka values of the variables) between them, a class can be utilized so that the user can repeatedly start out with the general design and change its properties, without having to build the design from scratch each time. Each time the blueprint is called an instance of the class is generated which creates a new object from the blueprint. In addition, classes contain built-in methods such as __str__(), __repr__() and __eq__() which provide various ways to represent the object being defined within the class such as by providing a human readable version, recreating an object with the same value or checking for equivalency between self and other.

     When coding a new class, "self" is the first parameter in any function defined inside the class. The purpose of this is to access functions and variables inside various methods in the class, from within the class itself. In order to do this the code "self.variable_name" must be called within the method, where variable_name represents the parameter of a function within the class. Alternatively, to access functions and variables from outside the class, the variable name assigned to the instance of the class must be called along with the name of the method you wish to access.

     Inheritance is the process of defining a new class based on another parent class. This new class inherits everything from the parent class while adding its own new attributes and methods to fill in missing pieces of information in the parent class that only a specific instance of the class could satisfy. To obtain this functionality, within the beginning of the code the name of the parent class must be provided in brackets after the name of the new class. In addition, any methods or attributes added to the new class that share the same name with the parent class are called instance variables and are capable of overriding the parent so that new definitions are used for the new class.

     Through the functionality described above, Object-Oriented Programming is able to group functions and variables together in classes so that they are in close reach of one another in order to make adjustments and work together through quick and efficient access to all required information.


No comments:

Post a Comment