Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Architecture question

Name: Anonymous 2009-05-02 17:38

Hello /prog/

I have developed a noteworthy Java program with over 20,000 lines of code. In the first version I threw things together the best I could think of at the time. Now that I've learned much about how it should be designed, I am refactoring it into something cleaner. However I am stuck with a situation that I can't figure out, and no amount of OOP design patterns seem to result in a good design.

I am reading several different types of tokens from a stream. Depending on the token, a different polymorphic object is created, but they all share the same superclass. These instantiated objects are then sent on their way for various purposes. There are two types of tokens I am struggling with in particular: I will call them token X and token Y. These two tokens are similar in many ways, for instance they both can be converted into binary data of a particular type. However, while it only takes 1 X token to create the data, it takes 2 Y tokens to create similar data. Additionally, the way they are converted into the end data differs somewhat, but they both require maintaining a state depending on what tokens came before.

So I have an X class, a Y class, a converter class for X objects, and a converter class for Y objects.

Since the converters have to persist and maintain state (depending on what came before), I can't really put them inside the X and Y classes because those will come and go. I could give the X and Y objects the converter class to briefly use and convert themselves to the binary data, but then the X and Y objects have to check that they are getting the correct converter class. On the flip side, I could pass the X and Y objects to the converters, but then the converters have to make sure they're getting the correct object type. All the while, the binary data will be produced immediately upon an X conversion, but will only happen on every other Y conversion (since it takes 2 Y objects to create the data).

So either way I'm regularly checking that these objects and converters are compatible, but there's got to be a better way. Any suggestions /prog/?

Name: Anonymous 2009-05-02 17:45

noteworthy
Java

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List