PDA

View Full Version : packages structure


panel
10-15-2007, 10:50 AM
Some time ago I started to build kind of framework (basicly containing usefull assets) and I wanna ask you about package naiming practices.
Let's say I am building some kind of player Player with own events and states.

First solution would be to put all classes in the same package
com.domain.video
---MyPlayer
---MyPlayerState
---MyPlayerEvents

The main disadvantage in this case for me it that MyPlayer class is in one package with 'helper' classes.


Secound aproach would be to split classes by 'type' and put them do diffrent packages.
com.domain.video
---MyPlayer
com.domain.consts
---MyPlayerState
com.domain.events
---MyPlayerEvents


I know it just metter of preferences. I just wanna know what do you think about secound aproach and how you deal with packages structure. Examples would be nice.

senocular
10-15-2007, 01:52 PM
This can be tricky, and I'm not entirely sure if there is a "standard" for this (anyone else is welcome to refute that). I usually go with keeping all classes that work together in the same package or the same sub package. This way, if I ever need that MyPlayer in another project, and I don't want to reference the original class location in my class path (say, in case I need to modify the class specifically for this new project), all I need to copy is one folder. That would contain all the dependencies for MyPlayer.

Now, that can vary depending on those dependencies. For example, if in MyPlayer I make a new generic volume class, for example, that could easily work in any project (and is likely to be used in other projects) then that would be separated from the MyPlayer package.

For what you listed, conts and events, I would probably keep them with MyPlayer