How I think class's work in Python
One of the methods we learn in the class, is trying to explain something to yourself, what is the code doing?
So here's what I came up with for Python Class....
Captain Picard walks up to the food replicator. He says, "Tea, Earl Grey, Hot"
The food replicator has a Class, called 'Tea'.
It looks up the next command, Earl Grey from the class, and knows what ingredients
need replicated, and what kind of tea cup he needs.... No it gets the command 'Hot', which it
also looks up in the 'Tea' class, and it says hot means 101 degrees.
That's what it makes for him.
Warf comes in, He wants Romulan Ale,
He tells it Romulan Ale, Tall, cold.
(which the replicator won't make because it's outlawed in the federation)
It does not find a Class Romulan Ale, and asks for a different selection.
He tells it Blood of Grexkkk, (I don't know Klingon) The replicator (python) says ok,
he want's the Blood of Grexkkk Class, and since he didn't ask for any specificity, it makes the Blood of Grexkkk for him with all the default settings stored in that class.
Eh, Work in progress, If I find out more, I'll update. That's what I got so far.
update: 1-18-18
I found a really old game I made when I did Zed's Learn Python the Hard Way book way back when it was free online. Holy cow.... I really had no idea what class's did. Because I avoided using them like the plague. The old code had not one single class in it.
So as I see it now, they are super useful storage containers. I'm redoing this old bit of code, and I have a questionaire class that holds a bunch of different pieces of another instance.... Pillogical(it creates questions and responses and prints them)
My game class can use this questionaire and get all these pieces and manipulate them to run the game without having to store the data, and if I decide I want to change the questionaire, the game stays intact, I just change the questionaire. Change my questions. The instances that are created somewhere else stay intact.... all I have to do... is change the text.
All of the code bits that I don't want to be changed yet, are in the Game class, and in the Pilliogical class, all I have to do to change up the interactive text is go into my Questionaire class and change the text... super useful storage containers.
Later we use the class's to build linked lists, nodes, dictionaries, More useful storage!
So, yeah.... Hey replicator, I would like a fully stocked laptop with the best processor and maximum memory capacity the market has to offer and remove the damned touch pad mouse while your at it. Linux if you please. Dual boot windows just for shit's and giggles, and hey, some buffalo mild boneless wings.
So here's what I came up with for Python Class....
Captain Picard walks up to the food replicator. He says, "Tea, Earl Grey, Hot"
The food replicator has a Class, called 'Tea'.
It looks up the next command, Earl Grey from the class, and knows what ingredients
need replicated, and what kind of tea cup he needs.... No it gets the command 'Hot', which it
also looks up in the 'Tea' class, and it says hot means 101 degrees.
That's what it makes for him.
Warf comes in, He wants Romulan Ale,
He tells it Romulan Ale, Tall, cold.
(which the replicator won't make because it's outlawed in the federation)
It does not find a Class Romulan Ale, and asks for a different selection.
He tells it Blood of Grexkkk, (I don't know Klingon) The replicator (python) says ok,
he want's the Blood of Grexkkk Class, and since he didn't ask for any specificity, it makes the Blood of Grexkkk for him with all the default settings stored in that class.
Eh, Work in progress, If I find out more, I'll update. That's what I got so far.
update: 1-18-18
I found a really old game I made when I did Zed's Learn Python the Hard Way book way back when it was free online. Holy cow.... I really had no idea what class's did. Because I avoided using them like the plague. The old code had not one single class in it.
So as I see it now, they are super useful storage containers. I'm redoing this old bit of code, and I have a questionaire class that holds a bunch of different pieces of another instance.... Pillogical(it creates questions and responses and prints them)
My game class can use this questionaire and get all these pieces and manipulate them to run the game without having to store the data, and if I decide I want to change the questionaire, the game stays intact, I just change the questionaire. Change my questions. The instances that are created somewhere else stay intact.... all I have to do... is change the text.
All of the code bits that I don't want to be changed yet, are in the Game class, and in the Pilliogical class, all I have to do to change up the interactive text is go into my Questionaire class and change the text... super useful storage containers.
Later we use the class's to build linked lists, nodes, dictionaries, More useful storage!
So, yeah.... Hey replicator, I would like a fully stocked laptop with the best processor and maximum memory capacity the market has to offer and remove the damned touch pad mouse while your at it. Linux if you please. Dual boot windows just for shit's and giggles, and hey, some buffalo mild boneless wings.
Not bad! We can talk about the subtleties sometime if you like :)
ReplyDelete