Richard,
in Order, is code like:
if (Status.isCancelled()).....
OrderStatus returns false - there is no cancelled status.
WorkOrderStatus does have a cancelled status and returns appropriately. One
of our clients, who uses a subclass of WorkOrder,lets say AcmeWorkOrder, has
of course an AcmeWorkOrderStatus class that adds a few statuses. This
particular client has 2 statuses that are effectively cancelled, but they
needed to differentiate from Client cancelled and Supplier Cancelled. So
the code way back in Order, if its actually an AcmeWorkOrder, will ask its
Status if its cancelled. But at runtime, it will be talking to an
AcmeWorkOrderStatus object, and behave correctly (cancelled orders may get
the option to reinstate etc).
All of the above is stored in metadata xml documents, and c# code is only
needed where lower-level business rules are required. The runtime manages
all of the construction; it only constructs the most recent Status, and
equates all prior instances to it, so the Status inside points to the same
instance as the "new" Status in subclasses.
Maybe this was a poor example to begin with. WorkOrders have a collection
of WorkOrderItems. When you subclass WorkOrder to AcmeWorkOrder, you get
with it a collection of WorkOrderItems. But you want a collection of
AcmeWorkOrderItems, so you use the "new" operator. The WorkOrder class is
not abstract, but quite thin from a data point of view. It does embody all
of our design patterns, and so has a lot of code and virtual methods, but
only a few persisted fields. When we engage a client requiring Work Order
Processing, we simply subclass WorkOrder and WorkOrderItem, whack in a few
more fields the client requires and presto! A fully-tailored highly
functional Order Processing system in a matter of hours (the framework has a
built in O/R mapper with full schema syncronisation).
This would not be possible without the "new" keyword.
Richard Blewett said:
I still don't understand why Order has a Status unless some ***Order
classes don't provide their own specialized version of the status