File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes Refactoring to Patterns - pattern questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Refactoring to Patterns - pattern questions" Watch "Refactoring to Patterns - pattern questions" New topic
Author

Refactoring to Patterns - pattern questions

Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
good day, everyone !!

i have a scenario, let assume we have 10 web pages, with each contains html form in web application, and these 10 page having same functionality, which are allow user to keyin data, and when user click button, it will save user entered data into database with different respective tables, and finally diplay the message either success or fail to save.

now, i want to build a component for this scenario, what design pattern and perhaps steps you recommend?
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
applying this scenario into struts framework, and i thinking of come out a component to help me to do this job..

generally, i want this component to do following tasks:
1)detect the user clicked form button (so we know what form are coming in)

2)form data accepted and save into DB (believe have to apply design pattern here..what design pattern recommend ?)

3)generate result message(success/fail)

for information, this is school project for testing idea on writing component..

:-further description on struts flow

i design every page using DIFFERENT action paths(href) but SAME action type(actual class for action), i design this because i want every page make sure cross over the component which i planning to do ...

is there anyone have comments and advice of these ? thank you very much on time !!
[ September 08, 2004: Message edited by: Alvin chew ]
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982

now, i want to build a component for this scenario, what design pattern and perhaps steps you recommend?

In another thread, I have mentioned that you can use MVC. In the post below, if you are using Struts, I think you have already made use of MVC.

Nick


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982

i design every page using DIFFERENT action paths(href) but SAME action type(actual class for action), i design this because i want every page make sure cross over the component which i planning to do ...

is there anyone have comments and advice of these ? thank you very much on time !!

If you are implemented the system in this way, seems that all requests are routed to the same ActionDispatcher class, isnt it?

You may try to group those similiar actions/operations, and each group has its own ActionDispatcher. The seperation maybe based on the use cases.

This will improve the readibility and maintanence of the system.

Nick
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
Detail of MVC Pattern



Reference Website
http://java.sun.com/blueprints/patterns/MVC-detailed.html

http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/web-tier/web-tier5.html


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
2)form data accepted and save into DB (believe have to apply design pattern here..what design pattern recommend ?)



Pattern for Manage DB :: DAO (Data Access Object) Pattern

Solution
Use a Data Access Object (DAO) to abstract and encapsulate all access to the data source. The DAO manages the connection with the data source to obtain and store data.

The DAO implements the access mechanism required to work with the data source. The data source could be a persistent store like an RDBMS, an external service like a B2B exchange, a repository like an LDAP database, or a business service accessed via CORBA Internet Inter-ORB Protocol (IIOP) or low-level sockets. The business component that relies on the DAO uses the simpler interface exposed by the DAO for its clients. The DAO completely hides the data source implementation details from its clients. Because the interface exposed by the DAO to clients does not change when the underlying data source implementation changes, this pattern allows the DAO to adapt to different storage schemes without affecting its clients or business components. Essentially, the DAO acts as an adapter between the component and the data source.




Reference Website
http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982

2)form data accepted and save into DB (believe have to apply design pattern here..what design pattern recommend ?)

If you are using legacy system, you may need to use JCA as well.

Nick
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
so, mr.Somkiat Puisungnoen, you recommend using factory pattern for solution ?
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
refer to my case, if i use my own action class instead of build-in action(forwardAction,dispathAction.. ), would u recommend ?

meaning say i have 10 pages, so i have 10 action path in each page(href=/action/page1,href=/action/page2 ..), but inside struts-config.xml, i put all action path pointing to my own defined action type = controller.action.product.ForAllPageAction,

this ForAllPageAction class (what pattern i should apply?)is actually doing all the function by import other class like store DB, check user clicked form, set message..and so on

would it be good by doing this ?
[ September 08, 2004: Message edited by: Alvin chew ]
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982

meaning say i have 10 pages, so i have 10 action path in each page(href=/action/page1,href=/action/page2 ..), but inside struts-config.xml, i put all action path pointing to my own defined action type = controller.action.product.ForAllPageAction,

this ForAllPageAction class (what pattern i should apply?)is actually doing all the function by import other class like store DB, check user clicked form, set message..and so on

would it be good by doing this ?

In your case, it is already the MVC pattern. The ActionDispatcher is already the controller of your system.

As I said before, you may consider grouping some actions together, for example, customer info related, into, say CustActionDispatcher, while the rest are defined based on the use cases.

Thus, your design can be cleaner.

Nick
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
ok..nicholas...i will check out on Actiondispatcher ...thank you !
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Originally posted by Alvin chew:
ok..nicholas...i will check out on Actiondispatcher ...thank you !


Yeah, Alvin, ActionDispatcher is essential in Struts applications... The role of ActionDispatcher is very important...

If you are using Struts, it's not a big deal to learn about that and apply it to your project...


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
is pattern able to apply any scenario ?
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Alvin chew:
is pattern able to apply any scenario ?
What do you mean by that?


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
meaning is pattern able to apply to everywhere, every scenario means every situation/cases ?
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Alvin chew:
meaning is pattern able to apply to everywhere, every scenario means every situation/cases ?
No. Patterns are almost explicitly applicable within a certain context where certain forces are in effect. Take a look at the Core J2EE Patterns online catalog to get an idea of how each pattern has a specific type of situation where they are most useful.
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
so meaning, pattern still require further research for improvement and perhaps more pattern come out in future ?
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982

pattern still require further research for improvement and perhaps more pattern come out in future ?

For sure.

Researchers do such research day and night. In fact, there are lots of different systems, which are not that easy to be covered by 10 or 100 or 1000 patterns. Each of them may have slight difference, which the patterns may not directly applied.

As I said, different systems will need to have its own study.

Nick
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Originally posted by Nicholas Cheung:

As I said, different systems will need to have its own study.

That's what Computer Scientists do in the research lab.... I.T. people are waiting for the result of research of Computer Scientists and apply it to the real world project with a better solution....
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982

That's what Computer Scientists do in the research lab.... I.T. people are waiting for the result of research of Computer Scientists and apply it to the real world project with a better solution....

Not only the underlying theories, but also the system aspect.

I need to do some research on every system/project I came across before I start working with my team. Usually, different people raise out different ideas, like what we are doing now, and if you missed something, you may make a wrong decision.

Nick
Alexandru Popescu
Ranch Hand

Joined: Jul 12, 2004
Posts: 995
Originally posted by Ko Ko Naing:

That's what Computer Scientists do in the research lab.... I.T. people are waiting for the result of research of Computer Scientists and apply it to the real world project with a better solution....


Patterns are not born inside a lab. On the contrary the guys with very large experience are in fact the parents.

./pope
[ September 10, 2004: Message edited by: Ali Pope ]

blog - InfoQ.com
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Originally posted by Ali Pope:


Patterns are not born inside a lab. On the contrary the guys with very large experience are in fact the parents.

./pope

[ September 10, 2004: Message edited by: Ali Pope ]


Well, I was not intend to fix the word "lab" into the meaning of "physical laboratory with a bunch of instruments"... I mean it for a place where something is invented... The word "lab" in my sentence is just virtual...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Refactoring to Patterns - pattern questions