• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Refactoring to Patterns - pattern questions

 
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 834
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 834
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so, mr.Somkiat Puisungnoen, you recommend using factory pattern for solution ?
 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 834
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok..nicholas...i will check out on Actiondispatcher ...thank you !
 
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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...
 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is pattern able to apply any scenario ?
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Alvin chew:
is pattern able to apply any scenario ?

What do you mean by that?
 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
meaning is pattern able to apply to everywhere, every scenario means every situation/cases ?
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 834
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so meaning, pattern still require further research for improvement and perhaps more pattern come out in future ?
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
 
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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...
 
reply
    Bookmark Topic Watch Topic
  • New Topic