Thursday, February 19, 2015

Object Oriented Programming

All my programming experience has been with object-oriented programming, but I don't think I ever understood quite what that meant until learning about objects formally. And I'm sure that I won't have a complete understanding until I gain more experience with other programming paradigms like functional or declarative programming.

In object-oriented programming, different objects of different types interact with each other to store information and solve problems. Objects can be of different types to allow them to be best suited to their specific task. There are types built in to Python already (int, str, bool, etc.) or they can be created using a class.

For example, continuing with my previous discussion of a mental lexicon, we can create a class "Lexicon". To reiterate, our brains' file words into our vocabulary as if they were dictionary entries containing several specific pieces of information, and we refer to this dictionary as our mental lexicon. It will include information like pronunciation, subcategorization (possible complements), and meaning.

So, we know that this class will contain objects that are words, and that these objects will contain pieces of information necessary to be able to understand and use these words grammatically. We will first write an "__init__" method to initialize instances of class lexicon. In this method we can define several necessary parameters to add a word to the lexicon, such as meaning, pronunciation, and category. The "__init__ " method is one of several special class methods that can be accessed using specific syntax, some others are "__eq__", "__repr__", and "__str__".

Now that we have created this specific lexicon class, we can create subclasses that inherit its traits and expand into even more specific functions. For example, we could have a class "Synonyms" that stores alternate meanings of words, or a class "French" to use our lexicon with a different language. These subclasses would not only be able to inherit from the superclass "Lexicon", but would also be able to extend and overwrite its methods. We can see how being able to create such a specific type of object would greatly improve our efficiency in solving problems pertaining to language.


No comments:

Post a Comment