Re: [DoubleType-dev-en] Question Relaxer
Status: Alpha
Brought to you by:
eed3si9n
|
From: e.e <eed...@us...> - 2005-01-12 10:38:49
|
Hello,
e.e wrote:
> This idea of mapping XML document and object is called XML data binding.
> Relaxer is a XML data binding tool that uses RELAX NG as input.
> # There are other tools that does XML data binding.
> # Castor is more popular, I think. Other platforms have their own stuff.
> X-prefixed classes in org.doubletype.ossa.xml package generated by Relaxer.
>
> I put anything that needs to be saved into the file into my glyph
> language. This saves a lot of work because I only need to define it once
> in the schema and it would be in both Java object and XML.
So X-prefixed classes such as XContour would take care of saving and
loading data from .glyph file.
But from object-oriented perspective these classes are pretty "dumb",
because they only store the data and it doesn't have any behavior
associated with them.
To overcome this issue, Relaxer has a facility called abstract factory
to let me extend the X-prefixed classes. When Relaxer finds a
<contour> tag, it creates EContour object instead of XContour object.
# E is for extend, not Emulator
EContour defines methods such as display() and move(), so it's more
smarter because it knows what to do with the data.
As it turns out, most of the objects in DoubleType requires similar
operation such as displaying and moving. In that case, it would be
useful to define an interface so I can treat them the same way.
This way, I can put whatever objects in a list and let each object
decide how to display or move itself.
For example, take a look at GlyphFile class's display method:
public void display(Graphics2D g, AffineTransform a_trans)
{
Iterator i = createIterator();
while (i.hasNext()) {
GlyphObject object = (GlyphObject) i.next();
object.display(g, a_trans);
} // while
}
A point and a contour would have totally different logic for displaying
but GlyphFile doesn't have to know about it.
In other words, E-prefixed classes are acting as an adapter from
X-prefixed classes to GlyphObject based classes.
Design architecture such as abstract factory and adapter are called
Design Patterns. The following page lists some of the patterns that's
used in my code:
- http://doubletype.sourceforge.net/?DesignPatterns
Thanks,
e.e
|