<p>I have a little dilemma that maybe you can help me sort out. </p>

<p>I've been working today in modifying ASP.NET's Membership to add a level of indirection. Basically, ASP.NET's Membership supports Users and Roles, leaving all authorization rules to be based on whether a user belongs to a Role or not. </p>

<p>What I need to do is add the concept of Function, where a user will belong to a role (or roles) and the role will have one or more functions associated with them, allowing us to authorize a specific action based on if the user belongs to a role which has a function assigned. </p>

<p>Having said that, my problem has nothing to do with it, it's a generic class design issue. </p>

<p>I want to provide an abstract method in my base RoleProvider class to create the function (and persist it), but I want to make it optional to save a description for that function, so I need to create my CreateFunction method with an overload, one signature accepting the name, and the other accepting the name and the description. </p>

<p>I can think of the following scenarios: </p>

<ol>
<li><p>Create both signatures with the abstract modifier. This has the problem that the implementer may not respect the best practice that says that one overload should call the other one with the parameters normalized, and the logic should only be in the final one (the one with all the parameters). Besides, it's not nice to require both methods to be implemented by the developer. </p></li>
<li><p>Create the first like virtual, and the second like abstract. Call the second from the first, allow the implementer to override the behavior. It has the same problem, the implementer could make "bad decisions" when overriding it. </p></li>
<li><p>Same as before, but do not allow the first to be overriden (remove the virtual modifier). The problem here is that the implementer has to be aware that the method could be called with a null description and has to handle that situation. </p></li>
</ol>

<p>I think the best option is the third one... </p>

<p>How is this scenario handled in general? When you design an abstract class and it contains overloaded methods. It isn't that uncommon I think... </p>

[{'answer_id': 34832, 'author': 'James A. Rosen', 'author_id': 1190, 'author_profile': 'https://Stackoverflow.com/users/1190', 'pm_score': 2, 'selected': True, 'text': '<p>I feel the best combination of DRYness and forcing the contract is as follows (in pseudocode):</p>\n\n<pre><code>class Base {\n  public final constructor(name) {\n    constructor(name, null)\n  end\n\n  public abstract constructor(name, description);\n}\n</code></pre>\n\n<p>or, alternatively:</p>\n\n<pre><code>class Base {\n  public abstract constructor(name);\n\n  public final constructor(name, description) {\n    constructor(name)\n    this.set_description(description)\n  }\n\n  private final set_description(description) {\n    ...\n  }\n}\n</code></pre>\n\n<p>There\'s a rule in Java that supports this decision: "never call non-final methods from a constructor."</p>\n'}, {'answer_id': 34990, 'author': 'NotMe', 'author_id': 2424, 'author_profile': 'https://Stackoverflow.com/users/2424', 'pm_score': 0, 'selected': False, 'text': '<p>To answer the first part of your post, check out AzMan (Authorization Manager), which, incidentally, is built into windows.  It has the capability to specify operations which can be recombined into roles or assigned directly to users.</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/magazine/cc300469.aspx" rel="nofollow noreferrer">Check out</a></p>\n\n<p>To answer the second part of your question, I wouldn\'t use an Abstract class.  Instead just provide the functionality in the constructor and be done with it.  It appeasr you want the specified behavior, and you don\'t want it to change.  Why force descendents to provide the implementation.</p>\n'}]
['https://Stackoverflow.com/questions/34806', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1782/']