Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

15
  • 5
    Making methods virtual allows optional overriding. Your method should probably be public, because it might not be overridden. Making methods abstract forces you to override them; they should probably be protected, because they're not particularly useful in a public context. Commented Sep 4, 2019 at 14:50
  • 4
    Actually, protected is most useful when you want to expose private members of the abstract class to derived classes. In any case, I'm not particularly concerned about your friend's opinion; choose the access modifier that makes the most sense for your particular situation. Commented Sep 4, 2019 at 14:53
  • 4
    Your colleague was advocating for the Template Method Pattern. There can be use cases for both ways, depending on how interdependent the two methods are. Commented Sep 4, 2019 at 15:42
  • 8
    @GregBurghardt: sounds like the OP's colleague suggests always to use the template method pattern, regardless if its required or not. That's a typical overuse of patterns - if one has a hammer, sooner or later every problem starts to look like a nail ;-) Commented Sep 4, 2019 at 16:16
  • 3
    @PeterPerot: I had never a problem to start with simple DTOs with just public fields, and when such a DTO turned out to require members with business logic, refactor them to classes with properties. Surely things are different when one works as a library vendor and has to care for not changing public APIs, then even turning a public field into a public property of the same name can cause issues. Commented Sep 5, 2019 at 10:20