I have a baseball player super class
I have a left field, center field, right field, 3b, ss, 2b, 1b, catcher, pitcher that inherits from player.
So, let’s take the pitchers for example. Would a pitcher class be a super class inheriting from baseball player too? with starter, reliever, setup, closer being classes that inherits from pitcher AND baseball player class?
Would my pitchers arsenal be an interface? for example, fast ball, curveball, slider, changeup?
let’s say we have a new instance of pitcher called nolan, would nolan’s fast ball be a ‘composition’ since nolan’s fast ball relies on nolan, or in other words or doesn’t exist without him?
I’m stuck on composition..can someone shed some light following the baseball analogy..
To put this is simple terms, inheritance is an is-a relationship, while composition is a has-a relatiohship.
A pitcher is a baseball player, so a pitcher would inherit from a baseball player. Also, a pitcher has an arsenal of pitches, so that could be defined as composition, although aggregation may be more appropriate if pitchers have varying pitches that they use, as aggregation includes lists.