In Android ViewGroup
inherits from View
. A ViewGroup
is a container which holds Views
.
ViewGroup (LinearLayout)
View (TextView)
Why did folks at Android defined this relationship as Inheritance
instead of composition. As the ViewGroup
contains Views
shouldn't it be composition ?
I think you're getting too hung up on the wording.
A "ViewGroup" has every bit as much reason to inherit from a "View" as a "TextView", and "ImageView" or ... more to the point ... a "ScrollView" or a "SurfaceView" (the latter two both "contain things").
Perhaps "View" wasn't necessarily the best choice of terms ... but the class heirarchy makes complete sense. Regardless of what it's subclasses are named :)
IMHO ...