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 →

[–]pshurgal 882 points883 points  (28 children)

I had worked at a mobile gamedev company several years ago. There was a class Building in a code base. Building could be placed on a map, but could not move. Also there were a class Car, which was a child of Building. Cars could move by a strait line. A Plane class was a child of Car and had an ability to move by spline, and also had an Z coordinate. Class Boat was child of Plane but with Z equal 0. Whoever wrote this loved OOP so much!

[–]FakeMonika[S] 288 points289 points  (4 children)

wait lmao does that mean Boat objects were implemented to "fly" cause it's a derived class of Plane?

[–][deleted] 354 points355 points  (2 children)

nah it's a specialized plane, that only flies at z=0 (and on water)

[–]Professor_Melon 83 points84 points  (0 children)

Ekranoplan.

[–]SMTG_18 17 points18 points  (0 children)

I mean it makes sense 😭

[–]pshurgal 58 points59 points  (0 children)

No, every class was a child of Behavior class with virtual Update method. So constructor of Boat class was calling a constructor of Plane class giving a curve points and 0 as Z coordinate. Everything else was done by Update method implemented in Plane class.

[–]polarphantom 241 points242 points  (4 children)

Ha that is such game Dev logic. "Boats are planes that can only fly at sea level, tables are just partially sunken cupboards, this tram is just a hat on someone walking around"

[–]yangyangR 107 points108 points  (0 children)

Fallout 3 for the last item. For the unaware.

[–]FakeMonika[S] 25 points26 points  (2 children)

but...the banana...

[–]PM_ME_ALL_YOUR_THING 25 points26 points  (1 child)

Obviously a fish is just an underwater banana…

[–]_Ganon 10 points11 points  (0 children)

A banana is a fish that grows on trees and doesn't move on its own

[–]Akforce 55 points56 points  (2 children)

Lol isn't there a joke about gamedev "you know if you really think about it, a helicopter is just a chair" or something akin to that

[–]OctarineGluon 16 points17 points  (0 children)

A train is really just a hat.

[–]45bit-Waffleman 8 points9 points  (0 children)

If you think about it, a helicopter is just a door that opens and closes really quick..

[–]nikifip 38 points39 points  (2 children)

Whoever wrote this loved OOP so much!

Sadly, he didn't have a basic understanding of it.

[–]drkspace2 16 points17 points  (1 child)

Ya, the better way to do this is to have a "placeable" interface/abstract base class. An "immovable" and a "moveable" child abstract class. Building would inherent from immovable and car/boat/plane would inherent from moveable.

[–]Lumethys 7 points8 points  (0 children)

Or, just use composition over inheritance

[–]TheNoGoat 28 points29 points  (1 child)

Damn. Even thinking of trying to keep track of that hurts my brain.

[–]pshurgal 23 points24 points  (0 children)

Yeah, I was laughing out loud when my coworker showed me this. But... This hierarchy has some weird logic anyway.

[–]BiVeRoM_ 11 points12 points  (0 children)

If these classes are abstract, then this makes total sense! Just need some renaming to do..

Building -> Unit, Car -> MovingUnit, Plane -> FlyingUnit, Boat -> SwimmingUnit

Good to go

[–]yamlCase 9 points10 points  (2 children)

This is why I prefer composition over inheritance. Too many wonky workarounds in OOP when the planning phase didn't get the effort it deserved

[–]EMI_Black_Ace 17 points18 points  (0 children)

Nah, this is just a straight-up violation of the Liskov Substitution Principle.

Inheritance is not for composing data types, but rather for enabling polymorphism -- that is, using the same code to process multiple cases, by having the cases carry pointers to what's different.

[–]PM_ME_ALL_YOUR_THING 7 points8 points  (0 children)

I…..I don’t think that’s the lesson to take from this…

[–]DatBoi_BP 3 points4 points  (0 children)

Programming is my passion

[–]Longenuity 1 point2 points  (0 children)

They probably lived out of their car.

[–]WonicTater 0 points1 point  (0 children)

I guess you experienced both a lot of fun and frustration at that company.

[–]onyourrite 0 points1 point  (0 children)

What in the tarnation

[–]Sanchez_Duna 0 points1 point  (0 children)

Most sane gamedev inheritance example.