开发者

Set classes as something like Shape? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜