java - What design pattern would fit my needs? -
i have next class:
public class { private string a; private long b; private date c; //getters, setters, constructors }
and need able export excel different templates. example, 1 excel has next headers: b c
another excel has next template: b c
and template this: b a
what way design code format object according 1 template or another? there particular design pattern can at?
i think can utilize adapter pattern, need create different adapter different templates.
bind object adapter , logic in adapter assign value passed object template want fill values.
by making adapter can create new format without making alter in existing format, create code more maintainable , separate.
this rough thought concept can apply here, still have scope of making many modification in it.
adapter interface
public interface adapter { }
adapter class
public class format2adapter implements adapter { private long title; string subtitle; public void filltemplate(core c){ title = c.getb(); } }
format2adapter class
public class format2adapter implements adapter { private long title; string subtitle; public void filltemplate(core c){ title = c.getb(); } }
business object class
import java.util.date; public class core { private string a; private long b; private date c; public string geta() { homecoming a; } public void seta(string a) { this.a = a; } public long getb() { homecoming b; } public void setb(long b) { this.b = b; } public date getc() { homecoming c; } public void setc(date c) { this.c = c; } // getters, setters, constructors }
java design-patterns architecture
No comments:
Post a Comment