Lecture overview -- Keyboard shortcut: 'u'  Previous page: Factory methods -- Keyboard shortcut: 'p'  Next page: Privacy Leaks -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 28 : 29
Object-oriented Programming in C#
Reference types, Value types, and Patterns
Examples of Static Factory Methods

In class Point it may be relevant to construct both polar and rectangular points

/user/normark/oop-csharp-1/sources/c-sharp/point/class-static-factory-methods/Point-before.csA clumsy attempt with two overloaded constructors.


/user/normark/oop-csharp-1/sources/c-sharp/point/class-static-factory-methods/Point-after.csA better solution with static factory methods.


In struct Interval it would be natural to have a parameterless constructor, but it is illegal

/user/normark/oop-csharp-1/sources/c-sharp/interval/static-factory-method/Interval-before.csA clumsy attempt with two overloaded constructors and an illegal constructor.


/user/normark/oop-csharp-1/sources/c-sharp/interval/static-factory-method/Interval-after.csA better solution with static factory methods.


Chose a coding style in which factory methods are consistently named: Make...(...)