Set classes as something like Shape? [closed]
Is there a way you can go about in java开发者_开发百科, writing code, to accomplish what Java has when it comes to the relationship between "Shape" and "Ellipse".
For example when you are drawing you create a Rectangle.
Then when you go to paint that rectangle it asks for a "Shape". I want to be able to make my own kind of thing for a program I am writing. It would just be more convenient if I could do that.
Conveniently, many classes implement the Shape
interface. There's a snippet here and a more elaborate example here.
The question is a bit vague, but what you have posted looks like composition/aggregation.
Soldier and Enemy should have a common interface, and the AI should interact with that interface.
精彩评论