java - Design pattern / data loading solution -


i have been working on few projects involve loading data, remotely, local, json, xml. problem having due speed of development , changing minds of various clients finding designs rigid , them more flexable. have been trying think of reusable solution data loading, , advice imagine many of out there have had same problem.

what create generic loadingoperation abstract class, has member variables of type parser , loader, have parse() , loaddata() methods respectivly. parser , loader classed interfaces , classes implement these xmlparser , jsonparser, localloader , remoteloader etc. like have new class extends loadingoperation each thing loaded, weather thats local xml file, or remote json, or whatever.

the problem is specific parser implementation cannot return custom data types without breaking polymorphic behavior of loadingoperation class. have been messing around generics , declaring subclasses of loadingoperation

class specificloader extends loadingoperation<customdatatype> 

and doing similar things parser classes, seems bit weird.

does have suggestions on im doing wrong / doing better. want able react changing specifications (ignoring fact shouldnt changing much!) , have logical seperation of code etc...

thanks help!

edit:question asked here link text

it sounds me want softly typed little code possible demands changing quickly. here how doing project of mine use php end. use sql , json data quick out of database , returned client.

typically select in database, each result row, convert row map each column becomes key value result column. list of maps transformed json through generic json rutine , json sent server.

a setup extremely easy transport data server client, but:

  • you loose type safety using hibernate/xml/remoting.
  • your clients tightly coupled database schema.
  • it though wicked fast grab data , transport it.
  • if change query more data, no recompile of clients needed unless need use new data.

to give idea of how looks in php do:

in data access object:

function getallportal() {     $sql = "select firstname, lastname, u.* person, portal_user u id=person order firstname, lastname";     $prep = $this->db->prepare($sql);     return $prep->execute(); } 

and in http service (rest based) code:

    $accperson = new accountperson($db);     echo json_encode($accperson->getallportal()); 

to in java need make framework getting data out in list of maps (or other easy structure want transport clients). made 1 in php allows use of prepared statements.

some other considerations consider (even if don't above) be:

avoid layers. have few of them possible. if use hibernate - embrace it. use objects directly in queries , convert them json , ship out. layers make code robust if several people (or clients) need use data - make code reluctant change fast. knowing when layers , when not trick , resist long can. writing layers take time.

go xml or better json transport. don't go schema resist change xml , or serialization pojos. pojos great business logic, sucks data transport. if client thin enough, don't bother deserialize json objects again. use json directly. again, layers, trick know when recreating pojos gives business value, , when not. layers, resist putting in work until see value. writing/maintaining deserializers take time.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -