-
Notifications
You must be signed in to change notification settings - Fork 4
Gendarme.Rules.Smells.AvoidSpeculativeGeneralityRule(git)
Assembly: Gendarme.Rules.Smells
Version: git
This rule allows developers to avoid the Speculative Generality smell. Be careful if you are developing a new framework or a new library, because this rule only inspects the assembly, then if you provide an abstract base class for extend by third party people, then the rule can warn you. You can ignore the message in this special case. We detect this smell by looking for:
- Abstract classes without responsibility
- Unnecessary delegation.
- Unused parameters.
Bad example:
// An abstract class with only one subclass.
public abstract class AbstractClass {
public abstract void MakeStuff ();
}
public class OverriderClass : AbstractClass {
public override void MakeStuff ()
{
}
}
If you use Telephone class only in one client, perhaps you don't need this kind of delegation.
public class Person {
int age;
string name;
Telephone phone;
}
public class Telephone {
int areaCode;
int phone;
}
Good example:
public abstract class OtherAbstractClass{
public abstract void MakeStuff ();
}
public class OtherOverriderClass : OtherAbstractClass {
public override void MakeStuff ()
{
}
}
public class YetAnotherOverriderClass : OtherAbstractClass {
public override void MakeStuff ()
{
}
}
You can browse the latest source code of this rule on github.com
Note that this page was autogenerated (3/17/2011 1:55:44 PM) based on the xmldoc
comments inside the rules source code and cannot be edited from this wiki.
Please report any documentation errors, typos or suggestions to the
Gendarme Mailing List. Thanks!