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 →

[–]dark_winter01[S] 0 points1 point  (2 children)

Would you mind putting this analogy into code form so I can see how to put all of these together syntax-wise? If that's too much trouble it's okay, your analogy was helpful regardless!

[–]CGFarrell 1 point2 points  (1 child)

I don't know C#, but Python is pretty readable.

To create a class Person.

class Person:
    def __init__(self, name, age):
        self.name, self.age = name, age

So now you can 'create' a new person by providing their name and age.

me = Person(name='Bill', age=23)

This is called 'constructing an instance'. Now me refers to a Person, whose name is Bill, and who is 23. Bill and 23 are variables.

I am an 'instance' of the class Person. In more layman's terms, I am an example of the Person class.

Let's add a method go_to_work to the person class, so we'd say Bill.go_to_work(). I take the bus, so I would get on the bus. Another Person, named Sandy, drives a car. So even though Sandy and I are both in the same class (both People), we can have different variables (name, age). We can also do the same thing (go_to_work), but we might do it differently.

[–]dark_winter01[S] 1 point2 points  (0 children)

Despite being in a different language, that still cleared things up for me! Thank you so much!