I'm introducing classes to my students today. What's a good example to use? I'm thinking cats, dogs or cars...

I'm introducing classes to my students today. What's a good example to use? I'm thinking cats, dogs or cars, but that's so overplayed. Give me something unique Sup Forums

neets v chads

Tell them they should know that shit already

class person

class man
method earn_money

class woman
method menstruate
method complain

game enities

OOP is cancer tbqh

classes aka races of the human race. do it

Animals is the easiest to follow that's why it's overplayed.

Make an animal class with properties for numbers of legs, color, and bs and then create simple constructor methods and other nonsense so you can demonstrate something like

zebra.num_legs

And it would return 4. Or fifty if they are truly retarded.

this. OP, don't try to be unique merely for the sake of being unique. if the metaphor seems bad to you, then certainly find a better metaphor than the animals one, but don't go looking for one just because it's "overplayed". find one because you have a problem with the mental model students generate.

coming up with metaphors to teach students is like walking a minefield for various reasons. for one thing, you might end up with a metaphor that doesn't resonate with as many students. you can evaluate this, but if you're not a researcher in education then something tells me you don't know how to do this (to say nothing of not having the resources to run an experiment except with live classes, which is ethically really frowned upon). but aside from that, you might risk coming up with a metaphor similar enough to to be offensive to some student for some bullshit reason. if you don't have tenure, do you really want to risk a complaint spurred by you simply wanting to be edgy?

and to be clear, i'm not saying you shouldn't have freedom to teach the way you want (provided you think it's helping and there's no evidence that it's actually yielding worse outcomes), but i also feel very strongly that people who put themselves in precarious positions with their careers for *no* other reason than out of boredom arguably deserve to get burned.

or 5 if it's male

Use an actual software example. I never understood classes until I saw it in action. For example illustrate a pluggable multi-user web service architecture. You'll have a class for the main application, a class for a user's profile, classes for the web services and an abstract web service class they extend, maybe classes for "triggers" like a scheduled job that runs the job once every so often or upon user input. You can then also demonstrate things like interface patterns, abstraction, inheritance, polymorphism, etc. and their practical applications (what happens when we need to add a new type of Web service? We just create another class that extends the abstract web service class. What if a particular set of web services needs to be able to do certain common things? Create an interface or have them extend an abstract class which in turn subclasses the abstract web service class. Etc).

Or, if your students are dumb, maybe use the idea of a company in a cost tracking scenario where everything (employees and assets) inherit from a "resource" class with a cost associated with it, with a tree structure (e.g. Developer implements IndividualContributor extends Employee extends Resource).

>He's a STEMfag

The fuck is wrong with you?

he's trolling. he's not even very good.

but apparently he doesn't need to be that good to get you.

You don't understand I'm legitimately perplexed
Why would someone post that kind of reaction image next to
>He's a STEMfag
It doesn't make sense

he's (trollishly) making it out like being in STEM is cringeworthy or something.

do you not understand the image? or are you not understanding the premise of trolling?

help us to help you

class person
method eat
method shit

class black extends person
method steal

class african extends black
method play_bongos

class jew extends person
method get_account_balance
private method formulate_scheme

I didn't understand the image, it looks like a man with dentures shriveled in the sun

I remember my professor introduced the concept by making us read up on and write an implementation of particle swarm optimization.

This

sometimes memes spin off. try not to overthink things on Sup Forums.

-T. doesn't-understand-OOP

I hate that memes are a meme now
>here's a thing I like Sup Forums
It's a meme
>but it has qualities like...
Meme
>But it's objectively better than
MEME!

I honestly heard SSD's called a meme once, I didn't know if he was trolling or an idiot

Why do I still come here

that's not what i was talking about at all. did you just have a conniption?

...

Classes didn't make sense to me when they were explained as literally classifying code, and the animals thing didn't sense to me either. I understood how to make them but I didn't the see the point of classes and objects until I looked into how games work.

Show them a class called Zombie.
Make an object called Zombie1.
Show that you can do stuff like Zombie1.HP and Zombie1.move().

It's important that they understand why they would want to do something before you force them to memorize a bunch of syntax.

explane
how would that help?

Everyone is different but for me I find classes make more sense as blueprints than as classes.

Or you can just have a big list of zombie structs with functions that act upon zombie structs.
Thats semi-oop without having to resort to oopshit.

give an example
im a newbie learning classes in python but I'm having trouble understanding
pls

Sorry I thought you were trying to say my idea was stupid instead of actually wanting an example.

Imagine you're making a Mario clone and you want to put enemies in the game.

You'll make a class called Goomba. Inside the class, you declare all the variables and functions that Goombas are going to use. You can give it a variable called 'speed' and make it equal to 5. Any time you spawn a Goomba it's speed will default be 5 because that's what you set it as.

Then you can make a class called Koopa. In Koopa you can declare another variable also called speed and set it to something like 7.

Koopas and Goombas both have their own speed variable and they can be different. Even though in the code there are two variables with the same name they don't interfere with each other.

ok I see.
do subclasses have to support all of the paren'ts class's methods?

You should read into "inheritance" for info on that. I'm a shitty programmer so I'm afraid of misleading you if I try to explain anything past the basics.

In general yes, they children need to have all of the parent's methods and private member variables. It would not make sense for it to not support any parent data.

For example, a human parent class and a student subclass. A human has getName(), getBirthday(), getEthnicity(), etc. A student, also being a human, must have those methods too because students have names. birthdays, and ethnicities.

You can also override the methods to not return anything or return specific values if you want them to.

the one where you don't ask Sup Forums for advice on how to teach your class

i don't know, it just seems like a hindrance to do that
is it possible to just copy a class and some methods (or but some methods)

That just defies the logic and philosophy of inheritance. If I was in a situation where I wanted some parent methods to return null because I didn't need them, then I'd just do away with inheritance altogether.

That's why inheritance is generally looked down upon because it takes an inhuman level of foresight and careful as fuck design. Though, when it's done right, the polymorphism it provides is brilliant

"so overplayed"

hey mosby, those kids arent your friends, stop trying to wow them. theres a reason those metaphors are common- everyone fucking gets them,
Sounds like instead of introducing classes, you should attend one... ON TEACHING.

interface gender
class man implements gender
class woman implements gender
class transgender implements gender
class Christine W Chandler extends transgender

class WhitePrivilege extends Privilege implements HateSpeech, Normative
{

}

Vehicle (car, van, truck bike -> colour, doors, wheels, weight, capacity)
Residence (house, apartment, castle -> rooms, floors, bathrooms)
Communication device (landline, cellular phone, radio -> number, manufacturer, Pokeman Go capability)

Animal is perfectly fine too.

Both extend Human but neet implements the autist Interface

this

property of neet
>isVirgin:true
while chad
>isVirgin:false

just classes or inheritence too?
simple explanation of class is user defined type.
analogies like animals, vehicles are about inheritence, is-a relationship.

>Normative
>humans aren't allowed to have culture unless they are not white

Location
->Continent
->Country
->City
They all share a name and population number, and possibly ruler, but the continent wouldn't have a ruler and return null or something, and the country might have something like languages spoken.

How's this example? I think it's pretty good compared to most of the racist and sexist things in this thread

>modeling your class hierarchies on the real world instead of based on the data they need

banana monkey jungle

This.

You're taming his post way too seriously. Shitpost some meme that is offensive, but also somewhat true and scroll on bruh

I did Hell once.

I made an abstract class named Hell and I made children classes that represents one division of Hell.

Also obviously there were a lot of kinds of guards with different permissions. Some could operate in multiply division and such.

Also this for the residents.


Use method name like Lust, Greed..cut out heart etc.

Most of the time I use inheritance when I need to override default behavior of some class method from some library to suit my use case or when I'm implementing some pre-defined interface or abstract class.

If you wanted a class (call it A) that supports some of the methods of another class (B), but not all of them, then you might have A be the parent of B, since B will support all of A's methods, with the addition of a few of its own.

If they share some methods, but each have some unique ones, then you might want to have them both inherit from a common parent.

Sorry if this is confusing, but you're better off reading a book or going through an online tutorial or something.

He brought up a related topic you conversation Nazi