Friday 13 February 2015

W6: OOP too OP for me

    It's finally time for a "break". Our first term test and a1 results have been returned. I have been kicking myself for the stupid mistakes I made on the term test. I wish I had checked it over, but I was literally writing until the very last second before the exam invigilator said, "stop writing, pencils down!". Besides that, I am satisfied with both results and really wish I could take a break; instead, a2 for both my csc148 and csc165 classes have been released and I am once again, thrown into a state of panic.
 
    Looking back to the start of the semester, I must say, I have improved my understanding of many things in the course. I felt we were a little rushed in the end of csc108 so I wasn't comfortable with classes when we started csc148, but now I feel a lot more confident, as well as with other OOP concepts .

Everything in Python is an object, they are, what we call, "the basic building blocks".

Classes
Why do we use classes? Mainly to have a sense of "togetherness", so that functions we use are not separate but can be grouped, in which they become methods. Somewhat similar to its cousin, def. In classes we are able to define attributes and methods. An attribute is a characteristic of an object, such as a salary of an employee. Methods are operations we can perform with our object; for example, a cancellation of an account. During the first week or so, I was still getting familiar with the structure and design of implementing classes, as well as the special methods: __init__, __str__, __repr__, and __eq__.

Subclasses:
A (sub)class (or "child class") derived from the parent class; an analogy commonly used to portray classes and their subclasses. These are generally more specific for particular cases, than what the parent class covers, as well as having the ability to override certain methods of the parent class.

Have you heard about the object-oriented way of becoming wealthy?
No...?
Inheritance.

Inheritance:
As defined by Google, "derive (a quality, characteristic, or predisposition) genetically from one's parents or ancestors"). It's basically the same in programming as well. Subclasses, children, inherit "characteristics/attributes" from classes, parents. Here, they are inheriting methods and data that have already been written. One important rule of programming is, "DRY", Don't Repeat Yourself (as I've learned how "lazy" some fellow programmers are haha).

Property:
Trying to make something "private" but not exactly. We do this by adding two underscores "__" 's in front of a variable/function and Pythonista's (as Prof. Heap calls fellow programmers), are expected to realize and respect that code. Means you're not supposed to change it, but there's nothing actually stopping you from doing so.

#well this wraps it up for now.

No comments:

Post a Comment