[CSHARP-148] Factory methods vs constructors Created: 19/Jan/11 Updated: 02/Apr/15 Resolved: 19/Jan/11 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | 1.0 |
| Fix Version/s: | 0.11 |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Aristarkh Zagorodnikov | Assignee: | Robert Stam |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Currently, many classes in the C# driver have both public constructors and factory (Create) methods, with different functionality (i.e. factory method usually caches thread-safe objects like MongoServer and MongoDatabase). I wonder if constructors should not be public to promote use of factory methods (since subclassing such types isn't practical, the constructors should become private and said types should be sealed)? |
| Comments |
| Comment by Aristarkh Zagorodnikov [ 19/Jan/11 ] |
|
Documentation comments will do nicely, thanks. |
| Comment by Robert Stam [ 19/Jan/11 ] |
|
It's a good question, but I don't think I want to make the constructors private or the classes sealed. That would interfere with some mock object unit testing frameworks. What I will do is mention prominently in the documentation that appears in Intellisense that you probably want to be calling the factory method instead and that calling the constructor directly is only required in some unusual scenarios. Thanks for the suggestion. |