CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Forum has moved

New location: CSLA .NET forum


CSLA .NET Resources:
  • CSLA .NET forum
  • CSLA .NET home page
  • Object Design Question

    rated by 0 users
    Answered (Verified) This post has 1 verified answer | 2 Replies | 1 Follower

    Top 50 Contributor
    197 Posts
    MadGerbil posted on Wed, Jul 16 2014 8:23 AM

    I've the following object graph:

    Client Singleton
    Charges Collection
    Payments Collection
    ChargePayments Collection

    The Client object has the 3 collections as child objects.
    The Charges collection holds a collection of all charges to the client.
    The Payment collection holds a collection of all payments to the client.
    The ChargePayments collection manages the many to many relationships bewteen Charges and Payments.

    The balance on a charge is the total of all amount applied to that charge as located in the ChargePayments collection.
    The amount applied for a payment is the total of all amount applied for that payment located in the ChargePayments collection.

    When a payment is deleted (this can happen while creating the record) all the ChargePayments related to that payment are deleted which means the totals on any Charges that used that payment need to be updated.
    Likewise, if a charge is deleted the ChargePayments related to that Charge are deleted and the amount applied for each of the Payments needs to be updated.

    Long story short, the removal of items in the ChargePayments collection (and addition of items) needs to cause each member of the Charges and Payments collections to update their totals.

    POSSIBLE FIXES
    1: Should this be managed by the parent object such that the parent Client object flips through children collections updating values
    2: Should each Charge and each Payment have a reference to the ChargePayments collection and update themselves when the ChargePayments collection changes
    3: Is there a better way altogether to handle this?

    Answered (Verified) Verified Answer

    Top 10 Contributor
    9,475 Posts
    Verified by MadGerbil

    The less objects know about each other (or reference each other) the better - as a general rule.

    I'd probably have the root object listen for ChildChanged events and use that knowledge to tell the correct child object graphs to update themselves as necessary.

    Rocky

    All Replies

    Top 10 Contributor
    9,475 Posts
    Verified by MadGerbil

    The less objects know about each other (or reference each other) the better - as a general rule.

    I'd probably have the root object listen for ChildChanged events and use that knowledge to tell the correct child object graphs to update themselves as necessary.

    Rocky

    Top 50 Contributor
    197 Posts

    That is the route I ended up taking - it not only preserves the object integrity but it is the easiest to work with by far.

     

    Page 1 of 1 (3 items) | RSS

    Copyright (c) 2006-2014 Marimer LLC. All rights reserved.
    Email admin@lhotka.net for support.
    Powered by Community Server (Non-Commercial Edition), by Telligent Systems