Views: 13.6K
Replies: 3
Archived
|
Why? C# abstract classes without abstract membersI am familiar with abstract classes, interfaces, and the like.
What is not clear to me is why anyone would create a C# abstract class that does not have abstract members? (the C# compiler allows this). Example: public abstract class House { public void OpenDoor() [ Console.WriteLine("Door opens"); } } Juan Perez, Mar 15, 2011
|
|
Reply 1In some scenario, you might want to provide a default implementation for your class or if you don't want your derived classes will define their own implementation, then the member will not be declared as abstract.
Vivekananda P, Mar 16, 2011
|
|
Reply 2One of the primary benefit of this is to provide default implementation. This can be useful in couple of scenarios. Also, have a look at the Template Method pattern for a simple application of this.
http://www.dofactory.com/Patterns/PatternTemplate.aspx Rajesh Pillai, Mar 16, 2011
|
|
Reply 3public abstract class House
{ public void OpenDoor() { Console.WriteLine("Door opens"); } } It will not show complie time error. you can use this class as base class of other class Kamal Gupta, Mar 16, 2011
|