-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathapproaches.txt
66 lines (49 loc) · 2.75 KB
/
approaches.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Schema Walking & Callbacks
-----------------------------------------------------------------------------
Like the 4010 EDI Generation code, where the transaction set definition is
iterated and some dispatch method is called to render each segment as its
visited.
Upsides:
- Reordering sibling nodes requires only changing the definition, and not the
client code.
- Validation is simple, because we can compare the current segment definition
to the return value of the callback at each point.
Downsides:
- While the iteration is performed from the transaction set itself, the client
code needs to control the iteration to some extent, based on the appropriate
number of loop iterations.
- It's awkward for the callback must maintain state across multiple invocations.
There are no "closing tags" with EDI and the client code doesn't know when
items in the state can be discarded.
- Validating the maximum number of loop iterations is also awkward. Should the
number of calls be limited, potentially truncating loop iterations without
the client knowing? Should we allow the callback to be called one more time,
tempting the client code to violate the standard?
Unrestricted
-----------------------------------------------------------------------------
The client code generates the full X12 transaction as a string, without any
guidance from the transaction set definition.
Upsides:
- It's simple to implement. The client code has full control of iterating the
objects that need to be serialized (claims, claim lines, eg).
Downsides:
- Validation can happen only when the generation is complete, meaning there is
no way to tell which part of the code (eg stacktrace) created invalid output
without walking through the code base.
- Without significant effort, code written to concatenate strings based on all
kinds of conditions can become very unreadable. Using a DSL would probably
alleviate readability problems.
Incremental Parse Tree
-----------------------------------------------------------------------------
The client code *incrementally* generates the X12, yielding it to a parser
which incrementally builds the syntax tree. Alternatively, the client calls a
DSL which is a state machine, which builds the AST
Upsides:
- Validation happens as the X12 data is being generated, and invalid X12 can
be tagged with a stack trace, cause an exception, etc.
- Constructing the parse tree is less costly, as its being built directly from
the DSL instead of being reconstituted from the serialized string.
- The client code retains control flow, avoiding the awkwardness of callbacks
and event-driven X12 generation.
Downsides:
- Difficult to implement the state machine