1

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.

Zeveso
  • 1,274
  • 3
  • 21
  • 41

2 Answers2

2

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.

Kaj
  • 10,862
  • 2
  • 33
  • 27
  • @ Kaj I am trying to get the same relashion ship between two classes like "Shape" and "Rectangle" have. – Zeveso May 08 '11 at 01:25
2

Conveniently, many classes implement the Shape interface. There's a snippet here and a more elaborate example here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Not quite what I was looking for, but the link to shape gave me everything I needed to know! THanks! – Zeveso May 08 '11 at 01:26