Question

I'm working on a pretty simple problem, with design ramifications.

Please bear with me, while I describe the situation in vague terms. I have an entity, call it EntityA:

EntityA{
   attr1 : type1;
   attr2 : type2;
   . . .
}

This entity is stored within a database, and everything is working great.

As a new requirement, I need to add audit attributes to EntityA. Now I have:

EntityA{
   . . .
   whenCreated : Date (not null);
   whoCreated : User (not null);
   whenLastUpdated : Date;
   whoLastUpdated : User;
}

When adding the new columns to the database, I assign default values: whoCreated = System whenCreated = 24-Jan-2012.

Another part of the requirement is that I not show the "create" attributes on the screen, if they have the conversion/default values.

I know that I will need to place logic to test for this in the display layer. That said, however, something seems funny with explicitly placing the conditional logic there.

For example, instead of this:

if((entA.whenCreated != '24-Jan-2012') 
        && (entA.whoCreated != 'System')){
    showCreationAudit();
}

I think I should do something like this:

if( shouldDisplayCreationAudit(entA) ){
    showCreationAudit();
}

So, keeping in mind that I will likely run into similar situations, what is a good way to abstract the conditional logic for "weird" hard-coded values?

Was it helpful?

Solution

I am interpreting you question as, "I have a list of model objects, and some have default values and some don't...where do I decide what to show?"

I think the view layer is exactly where you wan't to handle this.

Model objects just hold the data, and have some methods on them for manipulating the data. It is the job of the view to determine how to display the data.

OTHER TIPS

Its good practice to filter data in the business tier rather than sending everything to presentation layer and decide weather to render or not. Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top