Results 1 to 2 of 2
Thread: Cross-Class Implementation
- 08-13-2012, 10:02 PM #1
Member
- Join Date
- Aug 2012
- Posts
- 1
- Rep Power
- 0
Cross-Class Implementation
So, I have a situation where I have a set of abstract classes that have to interact with themselves and eachother, but only within a certain implementation. This results in a situation where I have something that looks like:
Which I can implement with something that looks like:Java Code:public interface Map { public Location getNearest(Location l); }
Or something that looks like:Java Code:public class 2DMap implements Map { public Location getNearest(Location l) { //actual code goes here } }
In the first option, the 2DMap would be expected to handle Locations from other implementations- something from a 3D map or a hex grid, which it clearly could not do. The second option, however, does not compile, because it doesn't really fufill the method header.Java Code:public class 2DMap implements Map { public 2DLocation getNearest(2DLocation l){ //actual code goes here } }
This is something I could fix easily enough with casting- within each method cast the relevant types to what they need to be- but it feels like there should be a more elegant, OOP-friendly way do to so.
What would be the "correct" way to go about this? Mind, not just looking for specific answers to the example listed, but for this type of situation in general- abstract systems where the specific implementations work in the described way, but only within the implementation.
- 08-14-2012, 09:33 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,459
- Rep Power
- 16
Similar Threads
-
Abstract class, implementation, getName()?
By manalinik in forum New To JavaReplies: 2Last Post: 12-27-2011, 02:08 PM -
Cross linking (cross referencing) javadoc between projects.
By couling in forum Advanced JavaReplies: 0Last Post: 12-08-2011, 12:43 PM -
Class within one class implementation
By gomdohri in forum New To JavaReplies: 1Last Post: 10-18-2011, 02:05 AM -
Implementation Class for RMI App, Compile-Time Error
By Jacob1028555 in forum NetworkingReplies: 22Last Post: 06-09-2011, 05:14 PM -
Help with implementation of the DataSet class
By silvia in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:47 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks