s BUSINESS FRAMEWORK IMPLEMENTATION in VB.NET

Generate PDF417 in VB.NET s BUSINESS FRAMEWORK IMPLEMENTATION

CHAPTER 3 s BUSINESS FRAMEWORK IMPLEMENTATION
PDF417 Creation In VB.NET
Using Barcode encoder for VS .NET Control to generate, create PDF417 image in .NET applications.
www.OnBarcode.com
Reading PDF417 In Visual Basic .NET
Using Barcode scanner for VS .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Root, Parent, and Child Behaviors
Linear Barcode Printer In VB.NET
Using Barcode creator for Visual Studio .NET Control to generate, create Linear image in .NET framework applications.
www.OnBarcode.com
Printing USS Code 128 In Visual Basic .NET
Using Barcode generator for Visual Studio .NET Control to generate, create ANSI/AIM Code 128 image in VS .NET applications.
www.OnBarcode.com
2 introduced the idea that a business object can be a root, parent, and/or child object. A definition of each can be found in Table 3-7. Table 3-7. Root, Parent, and Child Object Definitions
Paint PDF-417 2d Barcode In VB.NET
Using Barcode encoder for Visual Studio .NET Control to generate, create PDF417 image in VS .NET applications.
www.OnBarcode.com
Print QR Code 2d Barcode In Visual Basic .NET
Using Barcode generation for .NET framework Control to generate, create QR image in Visual Studio .NET applications.
www.OnBarcode.com
Object Type
Matrix Generation In Visual Basic .NET
Using Barcode creation for .NET Control to generate, create Matrix 2D Barcode image in Visual Studio .NET applications.
www.OnBarcode.com
Draw Code11 In VB.NET
Using Barcode creator for VS .NET Control to generate, create Code 11 image in .NET framework applications.
www.OnBarcode.com
Root Parent Child
PDF417 Drawer In Java
Using Barcode drawer for Java Control to generate, create PDF 417 image in Java applications.
www.OnBarcode.com
Drawing PDF-417 2d Barcode In None
Using Barcode printer for Software Control to generate, create PDF 417 image in Software applications.
www.OnBarcode.com
Definition
Generate PDF-417 2d Barcode In Java
Using Barcode creator for Java Control to generate, create PDF417 image in Java applications.
www.OnBarcode.com
Barcode Recognizer In VS .NET
Using Barcode scanner for .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
An object that can be directly retrieved or updated via the data portal An object that contains other business objects as part of its state An object that is contained by another business object
Universal Product Code Version A Encoder In Java
Using Barcode creator for Android Control to generate, create Universal Product Code version A image in Android applications.
www.OnBarcode.com
Painting Barcode In .NET
Using Barcode generation for .NET framework Control to generate, create Barcode image in Visual Studio .NET applications.
www.OnBarcode.com
A root object may be a stand-alone object. It may also be a parent if it contains child objects. A child object could also be a parent if it, in turn, contains other child objects. An example of a root and parent object is an Invoice, while an example of a child object would be a LineItem object within that Invoice. Child objects are related to root objects via a containment relationship, as illustrated by the class diagram in Figure 3-3.
Data Matrix Maker In None
Using Barcode encoder for Office Excel Control to generate, create ECC200 image in Excel applications.
www.OnBarcode.com
Create Code 3 Of 9 In None
Using Barcode creation for Software Control to generate, create ANSI/AIM Code 39 image in Software applications.
www.OnBarcode.com
Figure 3-3. Class diagram showing how root, child, and grandchild objects are related
Quick Response Code Creator In Java
Using Barcode generator for Eclipse BIRT Control to generate, create QR-Code image in BIRT applications.
www.OnBarcode.com
ECC200 Printer In Objective-C
Using Barcode maker for iPad Control to generate, create ECC200 image in iPad applications.
www.OnBarcode.com
MarkAsChild
EAN13 Printer In VS .NET
Using Barcode creator for ASP.NET Control to generate, create EAN-13 Supplement 5 image in ASP.NET applications.
www.OnBarcode.com
Barcode Drawer In None
Using Barcode creator for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
The business programmer makes the choice about whether an object is a child or not through code. By default, an object is a root object, and is only considered to be a child object if the MarkAsChild() method is called in the object s constructor. The MarkAsChild() method looks like this: Protected Sub MarkAsChild() mIsChild = True End Sub The mIsChild field is used to maintain whether the object is a child, and that value is exposed via an IsChild property:
CHAPTER 3 s BUSINESS FRAMEWORK IMPLEMENTATION
<NotUndoable()> _ Private mIsChild As Boolean Protected Friend ReadOnly Property IsChild() As Boolean Get Return mIsChild End Get End Property Notice that the field is declared using the <NotUndoable()> attribute. Since this value will never change during the lifetime of the object, there s no reason to include it in an n-level undo snapshot. The IsChild property will be used within other BusinessBase code, and may be useful to the business developer, so it s declared as Protected. There are certain behaviors that are valid only for root objects, and others that apply only to child objects. These rules will be enforced by throwing exceptions when an invalid operation is attempted. The Delete() and DeleteChild() methods implemented earlier are examples of this approach.
Parent Property
If a business object is a child of a collection, then it will maintain a reference to its parent business object. As you saw earlier, this is required for implementation of System.ComponentModel. IEditableObject. To avoid circular reference issues with n-level undo and serialization, the field holding this reference must be declared with the <NotUndoable()> and <NonSerialized()> attributes. Without these attributes, UndoableBase will go into an infinite loop during CopyState(), and .NET serialization will create a much larger byte stream during serialization than is required. The value will also be exposed through a property: <NotUndoable()> _ <NonSerialized()> _ Private mParent As Core.IEditableCollection <EditorBrowsable(EditorBrowsableState.Advanced)> _ Protected ReadOnly Property Parent() As Core.IEditableCollection Get Return mParent End Get End Property Due to the fact that the mParent field is not serializable, its value must be restored by the parent collection any time that deserialization occurs. To make this possible, the collection will call a Friend method on the business object: Friend Sub SetParent(ByVal parent As Core.IEditableCollection) If Not IsChild Then Throw New InvalidOperationException(My.Resources.ParentSetException) End If mParent = parent End Sub This method is only valid if the object is a child object, and all it does is store the parent object reference in the mParent field.
CHAPTER 3 s BUSINESS FRAMEWORK IMPLEMENTATION
Edit Level Tracking for Child Objects
N-level undo of collections of child objects is pretty complex, a fact that will become clear in the implementation of BusinessListBase. The biggest of several problems arises when a new child object is added to the collection, and then the collection s parent object is canceled. In that case, the child object must be removed from the collection as though it were never there the collection must be reset to its original state. To support this, child objects must keep track of the edit level at which they were added. UndoableBase made use of an EditLevel property that returned a number corresponding to the number of times the object s state had been copied for later undo. From a UI programmer s perspective, the edit level is the number of times BeginEdit() has been called, minus the number of times CancelEdit() or ApplyEdit() has been called. An example might help. Suppose that there is an Invoice object with a collection of LineItem objects. If BeginEdit() is called on the Invoice, then its edit level is 1. Since it cascades that call down to its child collection, the collection and all child objects are also at edit level 1. If a new child object is added to the collection, it would be added at edit level 1. If the Invoice object is then canceled, the user expects the Invoice object s state to be restored to what it was originally effectively, back to the level 0 state. Of course, this includes the child collection, which means that the collection somehow needs to realize that the newly added child object should be discarded. To do this, the BusinessListBase code will loop through its child objects looking for any that were added at an edit level higher than the current edit level. In this example, when the Invoice is canceled, its edit level immediately goes to 0. It cascades that call to the child collection, which then also has an edit level of 0. The collection scans its child objects looking for any that were added at an edit level greater than 0, and finds the new child object that was added at edit level 1. It then knows that this child object can be removed. This implies that business objects if they re child objects must keep track of the edit level at which they were added. This can be done with a simple field and a Friend property to set and retrieve its value: Private mEditLevelAdded As Integer Friend Property EditLevelAdded() As Integer Get Return mEditLevelAdded End Get Set(ByVal Value As Integer) mEditLevelAdded = Value End Set End Property The purpose and use of this functionality will become much clearer in the implementation of the BusinessListBase class later in this chapter.
Copyright © OnBarcode.com . All rights reserved.