• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FBNS: Package structure review

 
Klaas van Gelder
Ranch Hand
Posts: 111
Java Linux PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have nearly completed my first version of the FBN application. I would like to get some comment on my package structure (and the division of the classes), which appears to be more specified than most of the examples I saw from others...
Maybe it is a bit overkill to have 3 separate packages for model, view and controller. Is it better to combine these ?

Furthermore, I made the MVC structure completely independent of the Swing gui, so that another (web-based ?) gui can be plugged in later easily. Therefore, only the ViewReference interface is part of the generic mvc structure, acting as what some call a "hook" to the gui.

All input is very welcome... :-)
Greetz, Klaas



nl.kvg.flybynight
(some test classes)

nl.kvg.flybynight.gui
(GuiException)

nl.kvg.flybynight.gui.controller
(GuiController)

nl.kvg.flybynight.gui.model
(FlightDataModel)

nl.kvg.flybynight.gui.view
(ViewReference)

nl.kvg.flybynight.gui.view.swing
(BookFlightAction, ConnectLocalAction, ConnectRemoteAction,
DestinationComboBoxModel, DisconnectAction, FlightDataTableModel,
FlyByNight, MainWindow, OriginComboBoxModel,
SearchAction, SwingActionFactory)

nl.kvg.flybynight.network
(FlightDataConnector, FlightDataImpl, FlightDataRemote,
FlightDataServerException, LockManager, RegisterFlightDatabase,
RemoteConnectionFactory, RemoteConnectionFactoryImpl)

suncertify.db
(Data, DatabaseException, DataInfo, FieldAdapter, FieldInfo,
FlightDataAdapter, FlightdataServices, InvalidSearchStringException,
RecordAdapter, SeatsNotAvailableException)
 
No�l Verdurmen
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you name the packages nl.kvg.xxx ?

I interpreted the structure of the package more or less given, since there has to be a package suncertify.db. I think it is inconsistent to not start all package names with suncertify. You can then make suncertify.gui.xxx etc.
 
Klaas van Gelder
Ranch Hand
Posts: 111
Java Linux PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx 4 this reaction. Indeed, most of the people appear to stick with suncertify as the package root.
In my thoughts, I considered suncertify.db as a given "external party" package, but that doesn not bind my to copy the package structure ? What if i would have to import more packages, with different package roots ?
Therefore, I choosed to use my (fictive) personal domain nl.kvg as the package root, which identify the classes as unique for me. Besides, I like to follow the common convention for naming packages.

I would like to hear more opinions on this issue. And of course feedback on the contents of my packages is still welcome :-)
Greetz, Klaas
 
No�l Verdurmen
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, I wonder why your LockManager is in the networking package? Doesn't your local client lock?

I would put it in the db package.
[ August 25, 2004: Message edited by: No�l Verdurmen ]
 
Klaas van Gelder
Ranch Hand
Posts: 111
Java Linux PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I only use locking in network mode, because the locking mechanism is only required when the database is concurrently accessed by different clients ! The locking mechanism is completely bypassed in local mode.
Therefore, I implemented locking in the remote class (FlightDataImpl) which of course belong to the network module.
Greetz, Klaas
 
No�l Verdurmen
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Klaas van Gelder:
No, I only use locking in network mode, because the locking mechanism is only required when the database is concurrently accessed by different clients ! The locking mechanism is completely bypassed in local mode.
Therefore, I implemented locking in the remote class (FlightDataImpl) which of course belong to the network module.


What happens then if one client accesses your db locally and another one accesses it remotely ? Doesn't that cause trouble?
 
Klaas van Gelder
Ranch Hand
Posts: 111
Java Linux PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When in remote mode, the db.db file resides on the rmi server, where normally no client will ever make a local connection to it. When a client chooses for local mode, he always use the local copy of db.db, so concurrent local and remote access to one and the same db.db file is not an issue IMHO. But that is a different discussion...
In this thread, i would like to stay with the issue of the package names and class distribution in it.
Any more feedback ???
 
No�l Verdurmen
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thing:

I would start the naming of the test-package with test.nl.kvg...., so you can filter it out before delivery.

And besides that, I think if your packages for the Model / View / Controller are large it may make sense to define them in separate packages. But since the SCJD assignment is not that big I throw them all in one package. I don't like packages with one class. The package name then adds no more clarity about the structure (or very little if you might extend it later) than the class name.

Good luck with it,
 
Klaas van Gelder
Ranch Hand
Posts: 111
Java Linux PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx, I will reconsider this. I am also in doubt whether packages with only one class are a good idea or not :-)
Grtz Klaas
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Klass,

Like No�l, I dont like the idea of a package with a single class - I don't think it adds to the comprehensibility.

I started by looking at your package names, and based on them (ignoring the class names themselves) trying to work out which package I would look in for the class to start up the client / start up the server. Unfortunately this was not obvious to me. My first choice (nl.kvg.flybynight.gui) only has an Exception class. Then I don't know whether to go for your controller package or your swing package. Note: This is a bit of a personal observation - different programmers look at code in different ways, so someone else could find the classes very quickly and easily.

I did consider using my own domain name as a package name, but decided that there was little value in it - since Sun had already given us the suncertify.db package, I decided to follow suit. For what it's worth, here are the package names I ended up with:



Regards, Andrew
 
peter wooster
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Andrew Monkhouse:
Hi Klass,

Like No�l, I dont like the idea of a package with a single class - I don't think it adds to the comprehensibility.

I started by looking at your package names, and based on them (ignoring the class names themselves) trying to work out which package I would look in for the class to start up the client / start up the server. Unfortunately this was not obvious to me. My first choice (nl.kvg.flybynight.gui) only has an Exception class. Then I don't know whether to go for your controller package or your swing package. Note: This is a bit of a personal observation - different programmers look at code in different ways, so someone else could find the classes very quickly and easily.

I did consider using my own domain name as a package name, but decided that there was little value in it - since Sun had already given us the suncertify.db package, I decided to follow suit. For what it's worth, here are the package names I ended up with:



Regards, Andrew



I agree with Andrew and follow Sun's naming convention, but I use a few less packages.


I end up with a lot of classes (52 named classes and many anonymous inner classes) but that's a result of using the Command and Observer patterns, SwingUtilities.invokeLater and threads. I'm not sure if this follows or violates the requirement of simplicity.
 
Klaas van Gelder
Ranch Hand
Posts: 111
Java Linux PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Andrew and Peter for your reactions !

Based on Andrew's feedback, I plan to drop using my personal domain :-( Bluh, it feeld like killing a part of myself.... ;-)

Besides, I indeed think that my packages are too detailed, and packages with one class are indeed not a very good idea. So I plan to remove the packages:
nl.kvg.flybynight.gui.controller
nl.kvg.flybynight.gui.model
nl.kvg.flybynight.gui.view

and place the classes
GuiController
FlightDataModel
ViewReference (interface)
directly in the ~.gui package.

I still hang on using a separate package for the Swing-based classes, because my core MVC implementation is view-independent, using a generic ViewReference interface to communicate with the controller.
If, later, another view is added, for example a Web-based view, an extra sub-package can be added under the ~.gui package, neatly separating the classes for the different possible views.

And Andrew, this is also the reason that you could not find the class used to start up the client in the ~.view package, because this class (FlyByNight) is part of the Swing-based gui.
Maybe it would be more intuitive to place it directly in the ~.view package. But then a class in a more general package (FlyByNight in ~.view) refers to a class in a more specific package (MainWindow in ~.view.swing), and i thought that this is no good practice, as classes in more specific classes may refer to classes in more general packages, but not vice versa... (Am I right in this ???).
An alternative is adding an extra package, for example called ApplicationRunner, containing the 2 classes for starting the client and the server.

This leads to the following proposal for my new structure:

suncertify.test
(some test classes)

suncertify.gui
(GuiException, GuiController, FlightDataModel, ViewReference)

suncertify.gui.swingview
(BookFlightAction, ConnectLocalAction, ConnectRemoteAction,
DestinationComboBoxModel, DisconnectAction, FlightDataTableModel,
MainWindow, OriginComboBoxModel, SearchAction, SwingActionFactory)

suncertify.network
(FlightDataConnector, FlightDataImpl, FlightDataRemote,
FlightDataServerException, LockManager,
RemoteConnectionFactory, RemoteConnectionFactoryImpl)

suncertify.db
(Data, DatabaseException, DataInfo, FieldAdapter, FieldInfo,
FlightDataAdapter, FlightdataServices, InvalidSearchStringException,
RecordAdapter, SeatsNotAvailableException)

suncertify.applicationrunner
(FlyByNight, RegisterFlightDatabase)

Maybe the classes in the applicationrunner package should be renamed to:
FlyByNightClient, FlyByNightServer
to make it more clear what they do.

I hope for some more feedback... thanx in advance !
Greetz, Klaas
[ August 26, 2004: Message edited by: Klaas van Gelder ]
 
Klaas van Gelder
Ranch Hand
Posts: 111
Java Linux PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And my final (?) structure...

suncertify.client
(FlightDataConnector
FlightDataModel
GuiController
GuiException
ViewReference)

suncertify.client.swingview
(BookFlightAction
ConnectLocalAction
ConnectRemoteAction
DestinationComboBoxModel
FlightDataTableModel
MainWindow
OriginComboBoxModel
RunClient
SearchAction
SwingActionFactory)

suncertify.db
(Data
DatabaseException
DataInfo
FieldAdapter
FieldInfo
FlightDataAdapter
FlightDataServices
InvalidSearchStringException
RecordAdapter
SeatsNotAvailableException)

suncertify.network
(FlightDataImpl
FlightDataServicesRemote
LockManager
RemoteConnectionFactory
RemoteConnectionFactoryImpl)

Any comments are still welcome... :-)
Greetz, Klaas
[ August 29, 2004: Message edited by: Klaas van Gelder ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic