I’m developing a class for Persons and I’ve got a question or two about it.
/**
* ADT for persons which is completed which subclasses
* to creating actors with specific properties
*/
public class Person {
/**
* Name of the Person.
*/
public String name;
/**
* The World which this Person is associated with.
*/
public World world;
/**
* Tells where this Person is at the moment.
*/
public Place where;
/**
* The inventory, contains Things.
*/
public Collection<Thing> inventory;
/**
* Shows how the Person looks like
*/
public Image appearance;
/**
* Create Person named `name' in world `world'.
*
* @param world The world where the Person is created.
* @param name Name of the Person.
* @param app An image used to display the Person.
*/
public Person( World world, String name, Image app ) {
this.world = world;
this.name = name;
this.appearance = app;
where = world.defaultPlace();
where.enter( this );
inventory = Collections.synchronizedCollection( new LinkedList() );
}
…
-
Should the Person class be public or could default access be better? Isn’t it a bit strange that a Person, a private Person should be public even though the meanings are not exactly the same here.
-
How should I handle the arning when my IDE warn about the
inventory = Collections.synchronizedCollection( new LinkedList() );? It warns about my type safety.
Thank you
If Person will only be used in one package, you can make it default. Otherwise
publicmakes sense.Try giving the generic type.
BTW: Most IDEs will have an auto/quick fix for either of these problems.