code_junkie

How to implement classes which all use the same variables

Nov 12th, 2011
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. class Form : Document { ... }
  2.  
  3. // Later on
  4. Controls.Add(new DocumentDisplay(form));
  5.  
  6. class Form
  7. {
  8. private Document Document { get; set; }
  9. // Other stuff
  10. }
  11.  
  12. // Later on
  13. Controls.Add (new DocumentDisplay(form.Document));
  14.  
  15. class Document
  16. {
  17. List<Field> m_Fields;
  18. public void AddField(Field f) {... }
  19. public void AddFields(Field[] f) {... }
  20. }
  21.  
  22. class DocumentFactory()
  23. {
  24. public static Document GetDocument()
  25. {
  26. Document d = new Document();
  27. d.AddFields(GetDocumentFields()); // private helper .. returns fields 1-8
  28. return d;
  29. }
  30. public static Document GetForm()
  31. {
  32. Document d = new Document();
  33. AddDocumentFields(d);
  34. d.AddField(FIELD_9);
  35. d.AddField(FIELD_10);
  36. }
  37. // and so on..
  38. }
Add Comment
Please, Sign In to add comment