|
holy smokes! At first, OO programming sounded like more "theory" than reality. Up until now it seemed like a "strong possibility". Now it seems like "endless theory". :) When I see all this, I have to ask, is it really worth it? Why not do some OO and some procedural programming? Does anyone else have any thoughts on this? (I know Joe P's out for the week). - This post is purely rhetorical unless someone wishes to answer the above questions. This in no way is inteded to be a negative post, I'm just thinking out loud. All I wanted was to create some code that would let me choose XML or HTML and it's turning out to be a little more work that led on to be. :) but, we're learning. Brad > Ah. Add another level of encapsulation. > This is the solution to all design questions. You simply > encapsulate more, > and > if you find its difficult, you mix your encapsulation around a bit. > (Tongue in cheek ;-) > > Create 'MLAttribute' Interface and XML/HTML implementations of it. > The XXXFormatter and the XXXMLAttribute work together to > get the final goel done. > > Create abstraction so that Table, Row, Field use the generic Formatter > and MLAttribute objects. > > The user code does set up the tiny piece of code that cares > about WHICH > type of formatting is being done, all the rest is generic. > > > Table myTable = new Table(); > numRows = myTable.getNumRows(); > numFields = myTable.getNumFields(); > > GenericFormatter fmt = null; > MLAttributes tblAttr = null; > MLAttributes rowAttr[] = new MLAttributes[numRows]; > MLAttributes fieldAttr[] = new MLAttributes[numFields]; > > if (isXML) { > // First get very specific into the right type > // of formatter. > XMLTableFormatter xmlFmt = new XMLTableFormatter; > XMLMLAttributes xmlTblAttr = new XMLMLAttributes(); > XMLMLAttributes xmlRowAttr[] = new XMLMLAttributes[numRows]; > XMLMLAttributes xmlFieldAttr[] = new XMLMLAttributes[numFields]; > > xmlTblAttr = new XMLMLAttributes(); > xmlTblAttr.setWrapper("Table"); > > for (int rowN=0; i<numRows; ++i) { > // In reality, use 1 of these if the attributes for each > // row are the same. > xmlRowAttr[rowN] = new XMLMLAttributes(); > xmlRowAttr[rowN].setWrapper("Data"); > } > for (int fieldN=0; i<numFields; ++i) { > xmlFieldAttr[fieldN] = new XMLMLAttributes() > // Perhaps table is defined to use some appropriately > // generic setXxxx method on the attributes object > // for each time its called for a field. > // i.e. the table would do MLAttribute.setName() > // and an XMLMLAttribute might use that for the > // setWrapper() method, while the HTMLMLAttribute() > // might simply ignore it. > } > // Now go back to generic for the rest of the code > fmt = xmlFmt; > tblAttr = xmlTblAttr; > // Yes, this array assigment is compatible due to > // the relationship between the XMLMLAttributes and > // the MLAttributes objects. > rowAttr = xmlRowAttr; > fieldAttr = xmlFieldAttr; > } > else if (isHTML) { > // First get very specific into the right type > // of formatter. > HTMLTableFormatter htmlFmt = new HTMLTableFormatter; > HTMLMLAttributes htmlTblAttr = new HTMLMLAttributes(); > HTMLMLAttributes htmlRowAttr[] = new > HTMLMLAttributes[numRows]; > HTMLMLAttributes htmlFieldAttr[] = new > HTMLMLAttributes[numFields]; > > htmlTblAttr = new HTMLMLAttributes(); > htmlTblAttr.setHTMLOpenTag("<td>"); > htmlTblAttr.setHTMLCloseTag("</td>"); > > for (int rowN=0; i<numRows; ++i) { > // In reality, use 1 of these if the attributes for each > // row are the same. > htmlRowAttr[rowN] = new HTMLMLAttributes(); > htmlRowAttr[rowN].setHtmlOpenTag("<tr>"); > htmlRowAttr[rowN].setHtmlCloseTag("</tr>"); > } > for (int fieldN=0; i<numFields; ++i) { > htmlFieldAttr[fieldN] = new HTMLMLAttributes() > // Perhaps table is defined to use some appropriately > // generic setXxxx method on the attributes object > // for each time its called for a field. > // i.e. the table would do MLAttribute.setName() > // and an XMLMLAttribute might use that for the > // setWrapper() method, while the HTMLMLAttribute() > // might simply ignore it. > htmlFieldAttr[fieldN].setClass(myTable.getFieldClass(fieldN)); > } > // Now go back to generic for the rest of the code > fmt = htmlFmt; > tblAttr = htmlTblAttr; > // Yes, this array assigment is compatible due to > // the relationship between the HTMLMLAttributes and > // the MLAttributes objects. > rowAttr = htmlRowAttr; > fieldAttr = htmlFieldAttr; > } > > > myTable.setFormatter(new XMLTableFormatter()); > // In reality, might have a single set method > // if we desired to use one set of attributes > // for all rows. > for (int rowN=0; i<numRows; ++i) { > myTable.setRowAttributes(rowN, rowAttr[rowN]); > } > for (int fieldN=0; i<numFields; ++i) { > myTable.setFieldAttributes(fieldN, fieldAttr[fieldN]) > } > myTable.toML(); > > > > > "The stuff we call "software" is not like anything that human society > is used to thinking about. Software is something like a machine, and > something like mathematics, and something like language, and > something like thought, and art, and information... > but software is not in fact any of those other things." > Bruce Sterling - The Hacker Crackdown > > Fred A. Kulack - AS/400e Java and Java DB2 access, Jdbc, > JTA, etc... > IBM in Rochester, MN (Phone: 507.253.5982 T/L 553-5982) > mailto:kulack@us.ibm.com Personal: mailto:kulack@bresnanlink.net > AOL Instant Messenger: Home:FKulack Work:FKulackWrk > > +--- > | This is the JAVA/400 Mailing List! > | To submit a new message, send your mail to JAVA400-L@midrange.com. > | To subscribe to this list send email to JAVA400-L-SUB@midrange.com. > | To unsubscribe from this list send email to > JAVA400-L-UNSUB@midrange.com. > | Questions should be directed to the list owner: joe@zappie.net > +--- > +--- | This is the JAVA/400 Mailing List! | To submit a new message, send your mail to JAVA400-L@midrange.com. | To subscribe to this list send email to JAVA400-L-SUB@midrange.com. | To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com. | Questions should be directed to the list owner: joe@zappie.net +---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.