vendredi 2 octobre 2020

Uniformity in not-related objects in .Net

I have some classes, just plain POCO , like below. The factor class runs through series of classes and in the final step (class) the Port class data is saved in database beside doing other stuff that it does.

public class Factor
{
    public bool Result { get; set; }
    public string Iterator { get; set; }
    public string Message { get; set; }
    public Port Port { get; set; }
}

public class Port
{
    public int UpperLevel { get; set; }
    public int LoweverLevel { get; set; }
    public int Mid { get; set; }
    public int Error { get; set; }
}

Life was good, but life is not that simpler. Now I need some more objects in Factor class and I need to save their data to data base after passing through the series of classes (steps) same as Port.

public class Adjuster
{
    public decimal Angle { get; set; }
    public int Adjustment { get; set; }
}

public class Shifter
{
    public decimal Deviation { get; set; }
    public decimal Propotion { get; set; }
}

How I can bring uniformity in these three (Port, Adjuster and Shifter or more) unrelated classes so my Factor class take only one object [might be a marker interface?] (instead of injected these three – tomorrow I might have 10 more than I have to add 10 more to the factor class?) and work the proper way? One way I was thinking of could be Marker Interface, but I am not sure if that is the right way or there is a better approach to bring uniformity in unrelated object.

Any guidance will be appreciated...

Update The Factor class doesn't do anything on its own as shown in below code. It gets the data from one class and pass it to another class. I have updated the code to show where the Filter class is used. The Process method of Executor takes Filter and pass it to another class that is inline and process and sends the filter to another class and so on

public interface IProcessor
{
   Factor Process(Factor filter);
}

public class Processor : IProcessor
{
    private IEnumerable<IProcessor> Processors { get; }

    public Processor(IEnumerable<IProcessor> processor)
    {
      Processors = processor;
    }

    public Factor Process(Factor filter) => this.Processors.Aggregate(filter, (current, processor) => processor.Process(current));
}

Aucun commentaire:

Enregistrer un commentaire