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.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论