Monday, May 20, 2013

[android help] Android View and ViewGroup

Android View and ViewGroup - Stack Overflow







Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















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 ...























Viewgroup inherits properties of views and does more with other views and viewgroup






















I think this is a great example of the Composite design pattern:


http://en.wikipedia.org/wiki/Composite_pattern


Even though the naming might not be the best...




















default






.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...