Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. class Renderer
  2. {
  3. Tenant _tenant;
  4.  
  5. void Render(ContentType type)
  6. {
  7. switch (type)
  8. {
  9. case ContentType.JSON:
  10. _tenant.RenderJSON();
  11. break;
  12. default:
  13. _tenant.RenderHTML();
  14. break;
  15. }
  16. }
  17. }
  18.  
  19. class Tenant
  20. {
  21. virtual void RenderJSON() { ... };
  22. virtual void RenderHTML() { ... };
  23. }
  24.  
  25. class JoeBlow : Tenant
  26. {
  27. override void RenderJSON() { // joe blow's json };
  28. }
  29.  
  30. // uses a DefaultContentTypeDelegate
  31. IRenderer tenantADefault = new TenantARenderer();
  32. // specify a specific content type helper object
  33. IRenderer tenantAType1 = new TenantARender(new ContentType1Delegate());
  34.  
  35. class TenantARenderer : IRenderer {
  36. ...
  37. public render() {
  38. // do a bunch of tenant A specific stuff
  39. this.contentTypeDelegate.doSomeContentTypeSpecificStuff();
  40. // do some more tenant A stuff
  41. this.contentTypeDelegate.doSomeOtherContentTypeSpecificStuff();
  42. }
  43. ...
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement