I discover strange implementation in a .Net program structured as follows:
class Parent
{
..............
}
abstract class Child : Parent
{
..............
}
I start wondering whether the implementation is done correctly ? Because you cannot utilized the "Child" class object by initiating it, as it is marked as abstract or Is it a compilable code ???
After some surfing on internet, I come to realize that in .net framework every object is directly or indirectly inherited with System.Object class which is a non-abstract class and in our daily working environment we usually declares abstract calsses which are by default inherited with System.Object resulting in weird implementation structure but compileable under .net framework.
class Parent
{
..............
}
abstract class Child : Parent
{
..............
}
I start wondering whether the implementation is done correctly ? Because you cannot utilized the "Child" class object by initiating it, as it is marked as abstract or Is it a compilable code ???
After some surfing on internet, I come to realize that in .net framework every object is directly or indirectly inherited with System.Object class which is a non-abstract class and in our daily working environment we usually declares abstract calsses which are by default inherited with System.Object resulting in weird implementation structure but compileable under .net framework.
This is not weird at all. All this states is that the Child class must be inherited and can not stand by itself.
ReplyDeleteAgree with Tim.
ReplyDelete.Net framework allows you to keep a class either concrete or abstract, but what you do is your own choice. Whether your structure is weird or not depends on your own real world scenario.
Abstract class is 'weird'? Awesome post.
ReplyDeleteWhat is strange?
ReplyDeleteAbstract class can inherit abstract class
Interface can realize multiple interfaces.
I didn't get what you meant by weird?
I think all he means is it's weird to see code implemented in that fashion.
ReplyDeleteTo be fair it is a little why would you want to be able to instantiate the parent but not the child?
There could be valid reasons but it's not something you would do every day really.