cruft creator
cruft creator
cruft creator
cruft creator
cruft creator
You would probably need to parameterise any methods using that Collection.
Why are you making an inner class public
Why didn't you make that nested class static?
Why have you got private setters? Wouldn't methods that add something to your Collection have to be public?
cruft creator
cruft creator
cruft creator
Apologies acceptedmarten koomen wrote:sorry about the edit . . .
Defensive copies are a good idea. . . defensive copies . . .
In which case, I shall repeat that your nested class should probably be static.The inner class is public because these are the objects (Things) used by clients . . .
I should have read that sentence before saying the nested class should be static!. . . changed the nested class to static. . . .
orry. I see Stephan has also replied with a better solution.This works. So the inner class is now static and the class declaration looks like this - although I'm still playing around with the subclass
Why have you got private setters? Wouldn't methods that add something to your Collection have to be public?
Each Thing is available to multiple clients (through a web interface) where each client can make changes to Thing objects asynchronously, I have designed for changes to be made through a manager to ensure changes from multiple clients are made in an orderly fashion. The ThingManager is responsible for ensuring integrity of the database to which all changes are instantaneously written.
I also have rogue collections floating about (containing Thing objects marked as deleted but presented to clients after a search for possible un-deletion). So a ThingManager helps to keep track of this in single a Class.
I generally don't know if I'm just not programming very well, or if my domain is somewhat unique, I suspect a bit of both.
Note: A static nested class interacts with the instance members of its outer class (and other classes) just like any other top-level class. In effect, a static nested class is behaviorally a top-level class that has been nested in another top-level class for packaging convenience.
We always worry when we hear about singletons. Not sure I understand the last part of your reply:
I generally don't know if I'm just not programming very well, or if my domain is somewhat unique, I suspect a bit of both.
cruft creator
cruft creator
cruft creator
Thing's generic type parameter T is unused. Remove it.
You have public and protected members in a package private class.
Your constructors are redundant.
ConcreteThingManager's name can be shortened to Manager, because ConcreteThing already provides a separate namespace for it.
ConcreteThingManager's class header doesn't do what you think it does. Instead of using the class ConcreteThing, you introduced a new type variable named ConcreteThing.
Just using the word singleton should send shivers up your spine
cruft creator
You need to remove the type parameter R from Resource, because you're not using it anywhere (except in the self-referential type bound on R itself). You must leave it on your Manager class, because you actually use it there.
Don't use integers for IDs.
Don't expose fields. Sub-classes may access private fields though protected accessors.
What Java version are you on?
Don't do database stuff from constructors. Constructors must be lightweight. Let factory methods retrieve properties from a database and make the constructor accept the properties you want to set.
Instead of returning defensive copies from methods, return unmodifiable views
What is a TTException?
Return an Optional from methods instead of null
Use upper type bounds when accepting a collection from which to retrieve elements.
cruft creator
marten koomen wrote:I've changed the key to a String, Although I can't for the moment figure out how to abstract a Key into a class, will work on it.
jdk1.8.0_102
I understand this is not ideal, but I don't know how else to treat database exceptions elegantly for the browser based client.
I've been working to Joshua Bloch's Item 54, to not return nulls but empty collections, I'll need to double check that.
I'm understanding accept a Collection when that will do, rather an List.
<br /> I did this because my interpretation of the isOnPalette property led me to believe that having this field in Resource provides an opportunity for data inconsistency when its boolean value doesn't agree with whether the object is contained by the palette that the Manager manages. I normalized it by having the accessor return whether the resource was contained by the palette of the resource's manager. <br /> <br /> However, just as how elements don't know that they're contained by a set, it's probably best that a resource doesn't know that it's managed by a manager. I question the wisdom of having an isOnPalette property in the Resource class, if my interpretation of it is correct. Instead, clients should get this property by querying the manager.I don't understand why Resource needs a reference to the Manager, as it is the Manager that initiates and coordinates mutations to the Resource along with informing any other involved resources. I'll need to get my head around this.
A teeny tiny vulgar attempt to get you to buy our stuff
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
|