mardi 21 septembre 2021

Trying to get rid of many if else with factory method

    if (ftpType == "YouTube")
    {
        var digitalServiceResponse = JsonConvert.DeserializeObject<YoutubeMetadataResponse>(metadataJson);

        var fileRequest = new AddDeliveryFileRequest
        {
            //some code
        };

        ftpDeliveryQueue.AddFile(fileRequest);
    }
    else if (ftpType == "Flashtalking")
    {
        var metadata = JsonConvert.DeserializeObject<FlashtalkingMetadataResponse>(metadataJson);

        foreach (var file in metadata.FileList)
        {
            var fileRequest = new AddDeliveryFileRequest
            {
                //some code
            };

            ftpDeliveryQueue.AddFile(fileRequest);
        }
    }
    else if (ftpType == "Innovid")
    {
        var metadata = JsonConvert.DeserializeObject<InnovidMetadataResponse>(metadataJson);

        foreach (var file in metadata.FileList)
        {
            var fileRequest = new AddDeliveryFileRequest
            {
                //some code
            };

            ftpDeliveryQueue.AddFile(fileRequest);
        }
    }
    else
    {
        var digitalServiceResponse = JsonConvert.DeserializeObject<SizmekMetadataResponse>(metadataJson);

        foreach (var file in digitalServiceResponse.Metadata.FileList)
        {
            var fileRequest = new AddDeliveryFileRequest
            {
                //some code
            };
            ftpDeliveryQueue.AddFile(fileRequest);
        }
    }

How do I get rid of these if and else if block with the help of factory method?

Aucun commentaire:

Enregistrer un commentaire