Implemeting strategy pattern with multiple variables? [on hold]

I am trying to implement Strategy Pattern for handling my content serialization and deserialization. So I have four kind of requests namely CREATE, RETRIEVE, UPDATE, DELETE and for each request I want to serialize/deserialize the request and response content.

public interface ContentHandler{      String serializeRequest(Content con)();     String serializeResponse(Content con)();      Content deserializeRequest(String str)();     Content deserializeResponse(String str)(); } 

Now I will have four classes:

    public class CreateContentHandler implements ContentHandler{         String serializeRequest(Content con){            // .........             }         String serializeResponse(Content con){            // ........         }            Content deserializeRequest(String str){          }         Content deserializeResponse(String str){          }      }      public class RetrieveContentHandler implements ContentHandler{      //.........     }      public class UpdateContentHandler implements ContentHandler{      //.........     }      public class DeleteContentHandler implements ContentHandler{     //.........     } 

Now, I have a requirement to handle different content types like JSON, XML, CUSTOM-TYPE. So serialize content in JSON way or XML way.

So I was thinking of passing a contenType variable to each function and handle content inside each function by having switch cases.

   String serializeRequest(Content con, ContentType type){        // ....        switch(type){           case JSON:            case XML:         }     } 

But I think this will make my serialize function big with four different type handling. I have three variables serialize/deserialize, request/response, xml/json/cutom.

How can I add new interface or classes to cater different content types to the current design ??


Category: java Time: 2016-07-30 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.118 (s). 12 q(s)