This content has been marked as final. Show 2 replies
I have a Design pattern Question in Java/J2EEWhy do you think it's a pattern question? Does the exercise specifically recommends using a pattern? If not, you can design a solution with basic OO principles and "if" statements, it's not obvious you need a pattern at all.
Problem Statement::OK. Are these name/value pairs supposed to be the same information in two different formats, or do they represent different information? Must there be some consistency between them?
Suppose there are 2 files as below
XYZ.properties file --> name = value pair
abc.xml file --> attribute=value pair.
Both the above files have pairs.;)
The question is "Design a component/jsp page such that you can read,edit,save the name,value pairs of either a Property file or xml file.?"A JSP application to update a pair of files seems a strange architectural choice.
Do I understand well that those are files stored on the same server as the JSP engine is running?
Is the system supposed to support multiple concurrent users? If so you have a bigger problem (now that might deserve a "pattern").
So which Design pattern would you suggest i should be using in Java.?I don't get a few things:
The name,values pair are then fetched and displayed in another jsp page where i should be able to read,edit,save the name,value pairs such that
1>read operation results in reading the name,value pair
2>Edit operation results in editing the name,value pair
3>Save operation results in saving the value for the corresponding name,value pair in database and consequently updates either the property/xml file.
- when you "edit" (but not "save"), where is the information stored?
- if you have a database, why bother updating the property/XML file?
If your problem is to update the content of the DB, it's strange you start your post by mentioning the files instead.
My Initial Analysis : i would use a Factory design pattern since i have 2 files which have name,value pairs and at run time decide which one to choose* depending on the name of file invokedWhat is the type of the "one" you chose?
A factory method , or an abstract factory (just to remind you that factory is not a pattern in itself, and that you should describe more accurately your design) is usually meant to return an instance of one of the subclasses of a common class declared to be returned by the factory method, or to hide how the instance returned is created. But you do have to design which type of instance suits your requirements.
Returning a java.io.File object, as your posting suggests, misses the point that the content of the file will certainly need to be differently formatted, so it would be an awkward choice.
That is, if you want to use a factory (which isn't absurd). But you can also use other patterns, or no pattern at all.
Once done i would pass the parameters to jsp file for Read,edit and save operationWhich parameters? Are you talking about the query parameters in the URL, or about an object that represents the key/value pairs contained in the file?
Once done i would pass the parameters to jsp file for Read,edit and save operationWarning: except for an exercise, you shouldn't have business logic such as "save" in a JSP. Instead such business logic should be implemented in a model class (EJB, or POJO), or if it's a simple exercise, in a servlet class. JSPs should only be used to build HTML display out of Java objects created/updated by the business logic components.
Note that even as an exercise, those practice are questionable, since they teach you evil habits of which you won't get loose until you have understood the evilness in them...
Save would save the name,value pair to Database but i dont know how will it update the corresponding value for that name in either the property/xml file as well.*Well, assuming you are not afraid by the concurrent multi-user update of a server-side file, you can simply regenerate the whole file each time by iterating over the appropriate key/value pairs in the DB.
Feel free to give more info about your requirements, there much too much room for interpretation remaining; forum users will gladly help if they have enough information, but they won't want to spend time designing around unclear assumptions.
Certainly looks like a homework problem to me.
The statement of the problem doesn't lead to a pattern. It leads to an implementation.
As a pattern the Bridge is appropriate but overkill. As stated in GoF one uses that because one wants to avoid inheritence whereas the statement of this problem would be carried out by doing just that.
It has nothing to do with Factory. Factory is used to solve problems in creating objects. The problem description doesn't even address creation.