The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Regards, George
SCJP, SCJD, SCWCD, SCBCD
Regards, George
SCJP, SCJD, SCWCD, SCBCD
Seid Myadiyev<br />SCJP, SCWCD, SCBCD, SCEA-Part 1
Originally posted by George Marinkovich:
2) If you did so, I think you'd making your application unnecessarily brittle. Remember that you are coding to this format because it supports some legacy application over which you don't really have any control. So, what happens if the developers of the legacy application decide to start storing a new field, say "rating", in the database. So the developers of the legacy application change the contents of the database schema data to reflect the addition of the new field. When the user attempts to use this new database format with your application he will find that your application no longer correctly reads the database file. In fact, assuming you don't get some sort of fatal exception first, you'll see all sorts of garbled data when you display the contents of the database in your application.
This didn't have to happen. If you had been processing the database schema data section of the database file, your application would continue to work with the new database file format. Presumably the new "rating" field isn't of any interest to you so you may or may not display it in the GUI, but at least your application will be able to go on working despite the change to the database file. In other words, your application is robust.
Marco Tedone<br />SCJP1.4,SCJP5,SCBCD,SCWCD
Originally posted by Seid Myadiyev:
What is a better way to deal with the record status constants: valid and deleted? I know it would be acceptable to make them class constants because they are explicitly defined in the specification, but what would really be a best way? For example, read their value from the properties file, or make them final variables giving them flexibility to vary on each run (without the need to recompile). Or some other way?
Regards, George
SCJP, SCJD, SCWCD, SCBCD
Originally posted by Akhshay Ray:
Now if my DataSchema class reads its values from the file, then how can I make this class a Singleton?
Right now, my DataSchema class is a member variable of my Data class.
Regards, George
SCJP, SCJD, SCWCD, SCBCD
Originally posted by Akhshay Ray:
George,
For example, in some class someClass.java:
But then, it doesn't make any sense making the DataSchema Singleton.
So I was thinking of having two methods in DataSchema class:
public DataSchema createInstance(File file);
public DataSchema getInstance();
Now, is this too complex or violates the Singleton pattern in any way?
Thanks.
Originally posted by Akhshay Ray:
Well, think about how you'll actually want to use the schema data. It might be useful to you to have the following static accessor methods in DataSchema:
This way you don't really have to get the instance of DataSchema, but only the data within DataSchema that interests you.
But then, it doesn't make any sense making the DataSchema Singleton.
I don't think that's necessarily true. If it made sense to make the DataSchema class a singleton before, I'm not sure this invalidates that reasoning.
So I was thinking of having two methods in DataSchema class:
public DataSchema createInstance(File file);
public DataSchema getInstance();
Now, is this too complex or violates the Singleton pattern in any way?
Well I don't think it's too complex. As for violating the Singleton design pattern I don't think it does. It's still not possible to create more than a single instance of DataSchema, is it? That's really the only guarantee that the Singleton design pattern makes. The rest is merely convention. So if you use the static accessors described above then you would only need:
Regards, George
SCJP, SCJD, SCWCD, SCBCD
Don't get me started about those stupid light bulbs. |