mardi 11 avril 2017

Which approch is better accourding to oop rules and design pattern?

I'm trying to understand OOP SOLID principals and Design patterns. Here is a sample scenario Which I'm practicing with. Consider a media convertor app which accepts video, audio and photo files and each type has it's own different implementations of convert and different output extension. Properties like Id, FileName and Type is common but each type could have specific properties. for example Video file has video codec. I defined a base class which contains common properties. Here is my class:

public abstract class MediaFile
    {
        public abstract string OutputExtension { get; }
        public int Id { get; set; }

        public string FileName { get; set; }

        public MediaType Type { get; set; }
    }

public enum MediaType
{
    Video,
    Audio,
    Photo
}`

But I don't know should I define an abstract method named convert inside this class and override it into subclasses or I should define a separate interface for handling convert process according separation of concerns principal. I have defined my models into a separate assembly (should I?) and if I put another interface put in charge of convert process, if convert process needs to be changed, there will be no changes and no recompile to domain models assembly. but if I simply add an abstract method, implementing the class would be easier and less code is needed. I have uploaded two approaches that I took. Please if you can check them and clarify What I'm doing wrong? I want to follow SOLID principals and also Abstract design pattern. Thanks link to download sample projects

Aucun commentaire:

Enregistrer un commentaire