Skip to main content
gamedev.net
🔒 Locked

[java] Compiling Question

Started by cptrnet 2 replies 800+ views
Original Post
cptrnet
cptrnet
First off I think I am going overboard with making everything a class. I have these two classes in sperate packages and they rely on each other, and that makes for tight coupling which is bad right? Well I can't think of any reason why I should do it another way. The two classes are for collision detection, well actually they are interfaces. Collideable and CollisionListener Here is my directory tree source | ------com | ------impulse | ----event | | | -----CollisionListener | ----geometry | -----Collideable And here is my source for the two files

package com.impulse.geometry;

import com.impulse.event.CollisionListener;

public interface Collideable{

	public boolean isCollideable();
	public void    isCollideable(boolean c);
	public boolean checkCollision(Collideable other);
	public void    addCollisionListener(CollisionListener c);
	
}

package com.impulse.event;

import com.impulse.geometry.Collideable;

public interface CollisionListener{
	public void collisionEvent(Collideable one, Collideable two);
}

So here is my question assuming you don't think what I am doing is bad, because I am not really that good and I think I cam going to crazy with classes and interfaces and whatever. How do I compile these two files? I have tried every way I can think of and it says they both need the other file to compile. So I thought I can compile them at the same time but I get an error

C:\Java\engine>javac -d /class/ -cp /class/ C:/java/engine/source/com/impulse/ev
ent/*.java C:/java/engine/source/com/impulse/geometry/*.java
C:/java/engine/source/com/impulse/event/CollisionListener.java:21: error while w
riting com.impulse.event.CollisionListener: \class\com\impulse\event\CollisionLi
stener.class (The system cannot find the path specified)
public interface CollisionListener{

If you insist on saying "DUH", try to make a post that makes a little more sense
Son of Cain
Son of Cain
Quote:
Original post by cptrnet
public interface Collideable{

public boolean isCollideable();
public void isCollideable(boolean c);
//...


I won't comment on the error at hand, as I don't know the details of javac usage; Been using ant for too long, my brain is already frozen [grin]

Rather, I noticed the above quote on your code... If something implements Collideable, then Something IS COLLIDEABLE, it's unnecessary to check. So, in your code, all the entities that can be collided with will implement "Collideable"; Everything else is "not collideable" by default. Neat, uh?

An interface is a contract of methods that implementor classes need to provide in order to be used by a third part class that does not care about the implemention of said methods. In other words, your loop will need to update several Collideable objects, but it doesn't give a damn about how these instances handle their collisions. Got my point?

So, given such a point of view, it is right to assume that interfaces also qualify objects; Something can be "Movable", "Renderable", "Updatable", "Localizable"...

Son of Cain
a.k.a javabeats at yahoo.ca
CaptainJester
CaptainJester
Don't put your event listeners in a separate package. Put them with the classes that use them.

Quote:

that makes for tight coupling which is bad right?


Tight coupling is an indication to look at your package structure. See if they should be in the same package.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
LorenzoGatti
LorenzoGatti
Quote:
Original post by cptrnet
C:\Java\engine>javac -d /class/ -cp /class/ C:/java/engine/source/com/impulse/event/*.java C:/java/engine/source/com/impulse/geometry/*.java

\class\com\impulse\event\CollisionListener.class (The system cannot find the path specified)



Maybe you meant

C:\Java\engine>javac -d ./class/ -cp ./class/ c:/whatever.java

or equivalently

C:\Java\engine>javac -d class -cp class c:/whatever.java

because

/class/

is an absolute path, as the error message tells you.
Omae Wa Mou Shindeiru

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.