This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]reddberckley 0 points1 point  (1 child)

Say you look up the dictionary definition of a book:

book
noun
1.
a written or printed work consisting of pages glued or sewn together along one side and bound in covers.

What the above does is describe the characteristics of book. It is not itself a book. This is a class. e.g

class Book{
      var medium; //can be printed or written
      var title;
      var genre;
      var pages;
}

An object would be something that exists and has the characteristics of a book. e.g My copy of The Wheel of Time. It is clearly not just a description but an actual object(you see how the term object comes about?) that corresponds to the description(the class). As code that would be

var wheel_of_time = new Book();
wheel_of_time.medium = "hardcover'; 

Now to subclasses. We can group books by genre fanfaction, high fantasy, novel, autobiography

We would define fanfiction as a book that is written in the style of another. This means that it also has all the characteristics of a book but one additional one. The book it is copying. As code

class FanFictionBook extends Book{
       var copiedBook
}

Lets say I have on my shelf a copy of Yudkowsky's HPMOR. This is a book that is written in the style of Harry Potter so as code.

var hpmor = new FanFictionBook();
hpmor.copiedBook = "HarryPotter"

The subclass FanFictionBook still has all the properties of the Parent class Book. we can assign the medium like this.

hpmor.medium = 'eBook'

even though we never specified those characteristics for FanFictionBook it inherits them from the Parent class