Week 3: I’m learning about Objects wow!

I am gonna give you guys an introduction to Object Oriented Programming (OOP) with some bonus talk about Exceptions!

oop meme

I’d like to start my first blog ever by letting you know that Computer Science is my true passion everyday I remind myself of how privileged I am to have the opportunity to study not just something I love, but something I could potentially change the world with.

In my third week of CSC148 I have learned more about a fascinating concept called Object Oriented Programming (OOP). I really like how Object Oriented Programming makes it easy for us to maintain and modify our existing code as new objects that can be created with small differences to existing ones. I also learned about the abstraction that everything is an object and that objects serve two purposes; they know things (have attributes) and perform tasks.  Pretty much anything you can think of can be modeled into classes and have instances( that perform tasks) of them created. The possibilities are endless!

In my lab this week we learned how to implement a concept called Abstract DataTypes (ADTs). That is a certain class of data structures that have similar behavior and attributes. We made a basic ADT, Stack Class using OOP that can push new items on top of the stack, pop items from the top of the stack, indicate what item at the top is  as well as tell whether the stack is empty or not.

inheritance meem

Inheritance                                                                                                     After reading an article about inheritance on learnpythonthehardway.com I wonder why are we being taught inheritance if the readings says  Its something you should avoid, especially multiple inheritance at all costs? Well basically Inheritance is used to indicate that a  Child Class (Sub Class) will get most or all of its features from a Parent Class(Base Class).

There are multiple ways that the Parent-Class and the Child-Class can interact.

1) The child-class imply an action on the parent (a.k.a Implicit Inheritance)

you can put functions in the super class (i.e. Parent Class) then the child class will “INHERIT” those features, saving you time by not having to write 2 functions that perform the same task.

2) The child class can override the action(s) of the parent (Override Explicitly)                 The child can override a pre existing function it inherited from its parent class by defining it’s own version of that function with more functionality. No hard feelings Dad, my algorithm has better runtime! Lastly, you could do the exact same thing but in a nicer looking way by calling Pythons Built-in function super().

We are going to be diving into 2 more parts of OOP in the coming weeks such as Encapsulation and Polymorphism.

Exceptions                                                                                                                              I was exposed me to a new programming term called exceptions. In other words “Stop screwing with my code!”  I found understanding how to implement Python Exceptions difficult to grasp right off the bat. Which was frustrating, but after spending time reviewing the concepts starting with the basic exceptions I know feel more confident implementing them into my code. It is neat that we can develop custom exceptions that best fit our program and will most help the user understand their errors. I could make a custom exception that returns “Hey you, stop inheriting my money (bitcoins) I got it from object in the first place! ;)”

To hear more about my endeavors with CSC148 and Python stay tuned for more!

Until next time, Peace out!

yours truly,                                                                                                                       – “Code Shark”

Advertisements

3 thoughts on “Week 3: I’m learning about Objects wow!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s