Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Inheritance Question

Name: Anonymous 2011-11-21 12:54

Sup /prog/, self-learning programmer here. I have a question with inheritance. Say that I have a class called Food with an attribute "name" and "weight". Do I have to make subclasses with each type of food I will use (ie. apple is-a food, hence I need to make an apple subclass) or do I just instantiate a new food and call it apple? Note that I won't specifically give "apple" new attributes/methods, but I will make entities of it (ie. a person has 3 apples and 2 oranges blabla)

I realize this is a simple question but I'm a fucking baffled moron and can't seem to solve it.

Name: F r o z e n V o i d !!mJCwdV5J0Xy2A21 2011-11-22 0:50

>>6
enums are not useful for a "proper OOP" abstraction here. The fruit_list is just an array, you can't just declare another apple in the middle of code without changing the array.
what if you need food apple; in a another function? or returned from function? taking pointer to a struct is straightforward,as well as dereferencing it, unlike a single global array which would be aliased to dozen of functions and reused as some object pool(used for speed).

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List