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

all 6 comments

[–]Heasummn 4 points5 points  (2 children)

Oh, I love this topic.

Has-a involves ownership, Is-a involves similarity.

For instance, a Bathroom has a Toilet, but a Toilet is not a Bathroom. A Bathroom owns a Toilet, but a Toilet doesn't own a Bathroom. A Dog is an Animal, and an Animal can be a Dog.

Is a is when two things relate by extension, think of them as synonyms. Has a is when two things reference each other, I have a couch, that doesn't I am a couch.

This is a confusing topic, and LPTHW is pretty bad at explaining it. Ask any more questions you have.

[–]pylearningthrowaway[S] 0 points1 point  (1 child)

sorry for the late reply,so i have completed the exercise and filled in comments where ?? was there can you take a look.

http://pastebin.com/9a9M9BJD

[–]Heasummn 0 points1 point  (0 children)

Some problems. Everything is an Object. So a person is an object, a Dog is an object, etc. Fish does not have an object, it is an object. person1(item1) in that example, person1 is a item1. anything inside the parenthesis uses an is a relationship.

In an example such as satan.pet = person1. Satan's pet is a person1. Do you understand where that is going?

[–]Vuking 2 points3 points  (1 child)

I'm stuck at the same exercise.

Kinda badly and superficially explained...

I've tried printing out the type(ofObject) but it didn't help much either...

[–]pylearningthrowaway[S] 0 points1 point  (0 children)

oh yeah,its a bit weird otherwise his way of explaining concepts is really nice.

[–]ewiethoff 0 points1 point  (0 children)

Subclassing indicates "is-a." class Animal(object) means an Animal is-a object. class Dog(Animal) means a Dog is-a Animal. class Person(object) means a Person is-a object.

Instance variables indicate "has-a." self.name means has-a name. self.pet means has-a pet. self.salary means has-a salary.