Conceptual question

Conceptual question

Old forum URL: forums.lhotka.net/forums/t/2430.aspx


AGMs posted on Monday, February 26, 2007

Hello to all,

 

I have a conceptual question for my use case.

 

I have a win form where I create and maintain articles. I use a typical business object inheriting from BusinessBase with its validation rules and about 30 properties.

 

On the other hand, I must create another form where users may create articles massively, so users will supply a begin code and an end code, and will also supply the default values for properties.

A process inheriting from CommandBase will create the articles from the begin code to the end code.

As I’ve to validate the numeric interval of the begin code and the end code, I’ve to create two objects one for the normal creation and other for massive creation (CommandBase object apart)? In this case I’ll have two objects with a lot of common validation rules.

I don’t see the correct way to solve it.

 

Thanks in advance

RockfordLhotka replied on Monday, February 26, 2007

Having two objects is fine - reuse of properties shouldn't be a primary goal.

But reuse of the validation rules should be a goal. If you have custom rule methods, you can "normalize" them into a separate class that both your business objects can collaborate with to access the rules.

Also, you can normalize the AddBusinessRules() behavior, by having your business objects delegate the AddBusinessRules() call to a separate class (perhaps the same one).

Also, you may or may not need a CommandBase to do your work.

Assume you have ArticleEdit, which is your full-blown article edit object.

Then assume you have ArticleCreator, which is an editable root that only accepts the start and end codes. When you Save() an ArticleCreator, it can do the work to create the article from start to end in its DP_Insert() method.

If you are doing Windows Forms, you can then create an EditableRootListBase-derived collection of ArticleCreator, and you'd automatically get in-place grid editing, so the user can just add one after another into a grid. As they move off each row, the previous row's data would be immediately saved, causing that creation to occur.

Of course you can do a similar thing with CommandBase too - I'm just tossing out options here Smile [:)]

Copyright (c) Marimer LLC