Tuesday, 3 February 2015

Java XML design boolean flag and values



Here is what my current XML file looks like.



<book>
<isWritable>true</isWritable>
<writeDelay>4.0</writeDelay>

<isReadable>true</isReadable>
<readDelay>3.2</readDelay>

<isDestroyed>false</isDestroyed>
</book>


I have:


3 boolean flags - isWritable, isReadable, isDestroyed.


2 values writeDelay, readDelay.


Conditions:


isWritable require writeDelay


isReadable require readDelay


You can be isDestroyed but not isWritable or isReadable


You can be isWriteable and isReadable


You can be isWritable or isReadable


Current implementaion:


Book.class has all of these has required fields. I'm looking to simplifying this.


If my book is readable but not writable. The XML file should only be:



<book>
<isReadable>true</isReadable>
<readDelay>3.2</readDelay>
</book>


Likewise if the book is destroyed. The XML should only be:



<book>
<isDestroyed>true</isDestroyed>
</book>


Is there any existing design pattern that applies to my situation? I have looked at a few and am leaning towards polymorphism but wanted to reach out to see if there are any other patterns I have not yet considered.


Any comments and suggestions will be appreciated. Thank you!


No comments:

Post a Comment