Expert C# Business Objects by Rockford Lhotka - Chapter 7 - Business Object Implementation - CSLA.NET

Expert C# Business Objects by Rockford Lhotka - Chapter 7 - Business Object Implementation

----

I will be providing a chapter by chapter review of Expert C# Business Objects by Rockford Lhotka (Amazon) as well as any thoughts and commentary when appropriate. Enjoy.

Read Expert C# Business Objects Chapter 1.
Read
Expert C# Business Objects Chapter 2.
Read
Expert C# Business Objects Chapter 3.
Read
Expert C# Business Objects Chapter 4.
Read Expert C# Business Objects Chapter 5.
Read Expert C# Business Objects Chapter 6.

Chapter 7 builds templates to help the developer organize and create c# business objects that implement the CSLA.NET framework as well as actual c# business objects used to implement the sample project tracking application discussed in Chapter 6.

----

This is another chapter, like Chapter 3 - Key Technologies, that alone is worth the purchase price of the book. This chapter is where the rubber meets the road and the developer puts together all the .NET technologies and business base classes discussed in previous chapters and builds a solid framework for their project.

The chapter begins by providing an overview of the lifecycle of business objects. Sequence diagrams are used to help visualize the life cycle where the perspective is given from the UI viewpoint where objects are essentially managed. CSLA.NET uses “Class-In-Charge” for object creation, fetching, and immediate deletion which are exposed as static methods on the class.

Templates are created for various different types of business objects: editable root object, editable child collection, read-only NameValueLists, etc. that essentially can be used as a starting point for your own business objects. The following (see below) shows the common regions of a CSLA.NET business object.  I tosssed in some sample comments and data, but the chapter provides some really good detail on how these sections are implemented for various c# business objects. As a bonus, the reader also gets some good information about overriding basic object methods in your business components, whether you use CSLA.NET or not.

[Serializable()]
public class MyBusinessClass : CSLA.baseclass
{
    #region Business Properties and Methods

    #endregion

    #region System.Object overrides

    // overrides for ToString and various Equals

    #endregion

    #region Static Methods

        public static MyBusinessClass NewMyBusinessClass() { ... }

        public static MyBusinessClass GetMyBusinessClass() { ... }

        public static void DeleteMyBusinessClass() { ... }

    #endregion

    #region Constructors

        private MyBusinessClass()
       
{
            // Prevent Direct Creation
        }


    #endregion

    #region Criteria

    // Criteria for identifying existing object - example
    [Serializable()]
    private class Criteria
    {
        public int _id;

        public Criteria(int id)
        {
            _id = id;
        }
    }

    #endregion

    #region Data Access

    // private implementation of data access CRUD methods

    #endregion
}

The last half of the chapter takes the business object templates built in the first half of the chapter and applies them to the project tracking sample application designed in chapter 6. Here you see more useful code for actual data tables and business root objects (aggregates), child collections, and read-only NameValueLists. Real-world discussions of handling database transactions as well as making sure you process deletes in the databases first are also discussed in the end of the chapter. You also get to see the SafeDataReader and SmartDate objects in action to facilitate easier coding for the developer.

Certainly anyone walking away from Chapter 7 should have a pretty good understanding of CSLA.NET, business objects, and managing the business object lifecycle in general. Personally, the book could end here and I would be happy with the purchase.  However, it doesn't (bonus!). Now for the conclusion.

posted on Saturday, October 30, 2004 11:53 AM

Main

News

Green Tea

.NET Development

Enterprise Library

Patterns & Practices