The question I want to ask is this:
Throws an inheritance tree (i.e. towards a more specialized class) from within an abstract class, is forgiven or even good, or is it always a bad choice with better options?
Now, an example of why I think it can be used forever.
I recently implemented Bencoding from the BitTorrent protocol in C #. A simple problem is how to present the data. I decided to do it this way
We have a class abstract BItemthat provides some basic functions, including static BItem Decode(string)one that is used to decode a Bencoded string in the required structure.
There are four classes of derivatives BString, BInteger, BListand BDictionaryrepresenting the four different data type to be coded. Now here is the hard part. BListand BDictionaryhave attributes this[int], this[string]respectively, to allow access to the properties of these data types, like an array.
Now the potentially terrible part:
BDictionary torrent = (BDictionary) BItem.DecodeFile("my.torrent");
int filelength = (BInteger)((BDictionary)((BList)((BDictionary)
torrent["info"])["files"])[0])["length"];
Well, you get the picture ... Oh, it's hard on the eyes, not to mention the brain. So, I introduced something superfluous into the abstract class:
public BItem this[int index]
{
get { return ((BList)this)[index]; }
}
public BItem this[string index]
{
get { return ((BDictionary)this)[index]; }
}
Now we can rewrite this old code as:
BDictionary torrent = (BDictionary)BItem.DecodeFile("my.torrent");
int filelength = (BInteger)torrent["info"]["files"][0]["length"];
Wow, hey, preto, MUCH more readable code. But did I just sell part of my soul for implying knowledge of subclasses in an abstract class?
EDIT: , , , torrent["info"]["files"][0]["length"] , torrent["announce-list"][0][0] 90% . - , :(. , , 4 .