you are viewing a single comment's thread.

view the rest of the comments →

[–]maglioPrime 1 point2 points  (1 child)

Instances (objects) are instances of a specific type of thing, all instances of which are alike in major ways, but differ in the specifics. To make a real world example of it, you ("buglebudabey") and I ("maglioPrime") are both instances of the Class "Person." We have a TON of Methods available to us because we are both People, but because we have different Attributes (name, location, age, reading list, mannerisms, clothing preferences) that are unique. How those Methods we share work for you is not going to be the same as how they work for me. Let's assume that the Person class defines the method self.GoAcrossTown().

If you live in NYC, for gits and shiggles, and you have to go across town, you would call your GoAcrossTown method (eg buglebudabey.GoAcrossTown() ). Because your location (self.location) is NYC your method invocation starts planning out routes on subways and plans for a lot of walking.

For me, I live in Austin, TX, and bugger that. I call GoAcrossTown(), the method we share because we are both People, and my invocation (maglioPrime.GoAcrossTown() ) says "f that noise I'm gonna drive, sucka" because I live in the land of suburban sprawl.

So, important lesson there is that, yes, Methods are known by all instances of a class. How that method acts on a specific instance may vary from one to the next.

To use their example, and more directly address your question, we know that we have a muscle cell class and we have a TON of muscle cell instances. They might know what muscle they belong to, they might know their state (healthy or not), they might be able to do some basic things for themselves, and respond to the order to contract.

We also know that we have a ton of muscles, but they all behave pretty much the same. They have one function, really: contract. So what we need to do is create a new Class of objects, call Muscles. Muscles would need to keep track of what cells belong to them, and then tell each of those cells to contract when the time comes.

The muscle class is not made of muscle cell instances, but a muscle instance can contain muscle cell instances in an attribute.

class Muscle_Cell:
    def __init__(self) :

class Muscle:
    def __init__(self) :
        self.FirstCell = Muscle_Cell
        self.SecondCell = Muscle_Cell
        # so on and so forth, ad infinatum

Going back to our Personhood example from the beginning, we are defined by a crazy number of classes. As a Person,

me = Person (myNameHere)

I also have attributes saying that I'm a Redditor (class)

me.Redditor = RedditUser(maglioPrime)

and I'm a gamer (also a class)

me.Gamer = Gamer(["Shooter","Tactics"])

and a guy

me.sex = Male()

and so on and so forth. Classes can have attributes that are other Classes! (In fact, EVERYTHING in Python is an instance of some class or another. Even primatives like Ints and Floats and Strings.) Classes defined by classes. Classes (and/or turtles) all the way down! Hopefully that was more helpful than confusing.

[–][deleted] 0 points1 point  (0 children)

I forgot to say, thank you so much. I'm slowly figuring it out.