OOP Design Help

I have a c# code file (.cs) called MyReport.cs. Inside I have two classes, both public, called MyReport, and PositiveDecimalRule. The code is below.

The class name PositiveDecimalRule was a poor choice for a name in this situation because the rules inside are particular to MyReport only.

We now have a need to create a PositiveDecimalRule class that is more appropriate to all other reports in the same project.

Without renaming, is there another way too approach this problem? Also, ValidationRuleBase class is an abstract class, if that helps.

// MyReport.cs
public class MyReport : I1ActiveReport
{
	protected override void DoPrepareReport(Report report, ReportParameter sourceParameter)
	{
		...
		
		ReportParameter costOfFunds = ReportParameter.NewParameter("CostOfFunds", "Cost of Funds", 7, ReportParameterType.Decimal, 1, 1, false);
		costOfFunds.ParameterValues.Rules.Add(new PositiveDecimalRule());
		report.Parameters.Add(costOfFunds);
		
		...
	}
}

public class PositiveDecimalRule : ValidationRuleBase
{
	public override bool IsDataTypeSupported(RuleDataType ruleDataType)
	{
		if (ruleDataType is DecimalCollection)
			return true;
		return false;
	}

	protected override ValidationResultBase RunValidationOnValue(RuleDataType ruleDataType,
																 string friendlyFieldName,
																 RuleSettings settings)
	{
		DecimalCollection list = ruleDataType as DecimalCollection;
		if (list == null || list.Count == 0)
			return null;

		foreach (Decimal value in list)
		{
			string message = string.Empty;

			if (value < 1 && friendlyFieldName == "Monthly Cost Per Account")
			{
				message = "Must be a value greater than zero";
				return new ValidationResult(friendlyFieldName, message, ruleDataType, ValidationResultSeverity.Error);
			}
			else if (value < 0 && friendlyFieldName == "Cost of Funds")
			{
				message = "Must be a value greater than or equal to zero";
				return new ValidationResult(friendlyFieldName, message, ruleDataType, ValidationResultSeverity.Error);
			}
			
		}
		return null;
	}
}

Open in new window

LVL 8
pzozulkaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sarabandeCommented:
perhaps the class PositiveDecimalRule should be together with ValidationRuleBase?

Sara
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Carl TawnSystems and Integration DeveloperCommented:
You could move the existing PositiveDecimalRule class so that it becomes a nested class of MyReport and then use a second, public PositiveDecimalRule class for everything else.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.