Tuesday 27 January 2015

Subclass Sorcery

While I was already aware of classes before coming into the courses, the idea of subclasses was new to me. I had never really put any deep thought into the uses of classes but it makes sense that they would be used a templates for more specific classes (or rather subclasses).

When the topic was first brought up in class I was a bit confused as to how inheriting a class into another class was at all useful. Why bother creating a class that's just going to be part of a more specific and detailed class? Isn't that just making life more difficult?
I thought classes were for students...
 As the lecture developed I began to realize that making a main class to be inherited by subclasses isn't particularly useful when only using a single subclass such as the example. I had to expand the scope of my thought and consider that the lesson wasn't just about the particular example, but was intended to show how a subclass would inherit a class. The useful part of having a main class is when it gets inherited by multiple subclasses. It's a broad template that prevents you from having a ton of unneeded identical code scattered throughout your program. With this in mid it was easy for me to picture how classes would begin to form a branch-like structure where everything is connected to a mean trunk (or class) and it branches off into different subclasses which can continue to branch as needed. So instead of making a new tree every time you only need to add a branch to the one that's already there. It's classception!
So like a class... inside a class... inside a class...

No comments:

Post a Comment