Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you have functionality that you use frequently in classes that represent very different things, in my experience that should fall into just a few categories:</p> <ul> <li>Utilities (e.g. string formatting, parsing, ...)</li> <li>Cross-cutting concerns (logging, security enforcement, ...)</li> </ul> <p>For utility-type functionality you should consider creating separate classes, and referencing the utility classes where needed in the business class.</p> <pre><code>public class Validator { public bool IsValidName(string name); } class Patient { private Validator validator = new Validator(); public string FirstName { set { if (validator.IsValidName(value)) ... else ... } } } </code></pre> <p>For cross-cutting concerns such as logging or security, I suggest you investigate <a href="http://en.wikipedia.org/wiki/Aspect-oriented_programming" rel="noreferrer">Aspect-Oriented Programming</a>. </p> <p>Regarding the PrintA vs. PrintB example discussed in other comments, it sounds like an excellent case for the Factory Pattern. You define an interface e.g. IPrint, classes PrintA and PrintB that both implement IPrint, and assign an instance of IPrint based on what the particular page needs. </p> <pre><code>// Simplified example to explain: public interface IPrint { public void Print(string); } public class PrintA : IPrint { public void Print(string input) { ... format as desired for A ... } } public class PrintB : IPrint { public void Print(string input) { ... format as desired for B ... } } class MyPage { IPrint printer; public class MyPage(bool usePrintA) { if (usePrintA) printer = new PrintA(); else printer = new PrintB(); } public PrintThePage() { printer.Print(thePageText); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload