marcosrocha85 / delphi-clean-architecture

A Delphi Clean Architecture Example
MIT License
7 stars 6 forks source link

Mappers #3

Closed marcosrocha85 closed 5 years ago

marcosrocha85 commented 7 years ago

Implement an abstract class for Mappers. It should receive two generic parameters for a data and domain classes like so:

Java

    public abstract class Mapper<MODEL, DATA>
    {
        public abstract MODEL dataToModel(DATA data);
        public abstract DATA modelToData(MODEL model);

        public List<MODEL> dataToModel(List<DATA> list)
        {
            List<MODEL> models = new ArrayList<>();
            for (DATA data : list)
            {
                models.add(dataToModel(data));
            }
            return models;
        }

        public List<DATA> modelToData(List<MODEL> models)
        {
            List<DATA> list = new ArrayList<>();
            for (MODEL model : models)
            {
                list.add(modelToData(model));
            }
            return list;
        }
    }