> -----Original Message-----
> From: Matthew Small [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, April 04, 2007 3:16 PM
> To: CF-Community
> Subject: Re: Java Beginner: How would you do this?
>
> You can't create methods in abstract classes anyway. Just create a base
> class with all of your base methods, override the properties in an
> inherited class, and leave the methods alone. Call the base methods
> from your inherited methods:
You can defiantly create methods in abstract classes - that's what I ended
up doing. ;^)
If the method itself is marked "abstract" then you can't provide a body for
the method (basically acting just like an interface) but if the method is
marked as anything else then you can create it as you would normally.
I don't know if this is at all "correct" - but this how I ended up:
Two main objects:
AlphaWords:
Public class. The class has lots of properties accessed via setters/getters
that affect the output of the class (OutputPrefix, OutputPostfix,
OutputIncludeCSS, CharCSS and TransCSS).
One property takes a "WordList" which is of type "AlphaSet" as does the
constructor: public AlphaWords(AlphaSet NewAlphaSet).
This class accepts a string and outputs formatted work lists.
AlphaSet:
Abstract class. This class represents a word substitution list.
It has one abstract class, getWordList(), which returns the word
substitution list (provided by sub classes) and one public class,
getCharTrans(CharCode), which takes an ASCII code and returns the
substituted word/phrase (or a null for those cases when there is no
translation).
It has one private method, setTransTable(), which takes the word list and a
whole mess of standardized symbol translations and creates an array of
words/phrases who's indexes match the ASCII character code.
Alphabets:
Alphabets are generated by extending AlphaSet and implementing
getWordList(). Here's a complete AlphaSet:
package com.depressedpress.alphaWords;
public class AlphaSet_lapd extends AlphaSet {
public String[] getWordList() {
String[] WordList =
{"Adam","Boy","Charles","David","Edward","Frank","George","Henry","Ida","Joh
n","King","Lincoln","Mary","Nora","Ocean","Paul","Queen","Robert","Sam","Tom
","Union","Victor","William","X-ray","Young","Zebra"};
return WordList;
};
public AlphaSet_lapd() {
super();
}
}
A simple implementation of all this might look like this:
// Instantiate AlphaWords with the "nato" alphabet
AlphaWords aw = new AlphaWords(new AlphaSet_nato());
// Set some properties for the output
aw.setOutputStyle("Verbose");
aw.setOutputPostfix("\n");
// Translate (and output) a phrase
System.out.println(aw.translateToString("I know Java!"));
This would output:
Uppercase "I" as in India
The Space symbol (" ")
Lowercase "k" as in Kilo
Lowercase "n" as in November
Lowercase "o" as in Oscar
Lowercase "w" as in Whiskey
The Space symbol (" ")
Uppercase "J" as in Juliett
Lowercase "a" as in Alfa
Lowercase "v" as in Victor
Lowercase "a" as in Alfa
The Exclamation Point symbol ("!")
Again I'm not sure that I like this... I don't like the "getWordList()"
method being public but Java doesn't expose "private" methods to children
and abstract methods can't be private anyway.
Since it also doesn't expose private variables to children in any way that
they can be overridden the only real option seems to be to make things
public.
How would you encapsulate a set of objects that only changed in the instance
data but where you wanted the instance data to be static? I'm sure there's
a better way than I've done.
(I also did a "single class" version where all the alphasets were just
embedded in the main class. It works just fine but any additional alphasets
require modification of the main code - not really OO.)
Jim Davis
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Deploy Web Applications Quickly across the enterprise with ColdFusion MX7 &
Flex 2
Free Trial
http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJU
Archive:
http://www.houseoffusion.com/groups/CF-Community/message.cfm/messageid:232027
Subscription: http://www.houseoffusion.com/groups/CF-Community/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.5