Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding an internal abstract method in another assembly

Im currently working on a c# project that uses another .net library. This library does (amongst other things) parse a sequence into a tree. All items are of some type that inherits from the abstract class Sequence. I needed to alter the behaviour slightly and subclassed Sequence myself (lets call it MySequence). After the tree was created, I could replace some tree nodes with objects of my own class.

Now, a new version of the library was published, and a Copy function with the following signature was introduced:

internal abstract Sequence Copy();

I tried to adopt my code to the new version and override it, but whatever I am doing, I get the two errors:

MySequence does not implement inherited abstract member 'Sequence.Copy()'
and:
MySequence.Copy()': no suitable method found to override

This makes sense, since it is abstract (--> it must be overwritten) and internal (--> it can not be overwritten, due to hidden visibility from outside the assembly)

So, the problem is, I understand why this is happening, but dont know what to do against it. It is crucial for my project to subclass Sequence.

And what I also dont understand is, why the internal abstract modfier is allowed in the first place as it basically permits any subclassing of the whole class from outside the assembly!?

Is there any way to solve this? Via reflection or something?

Thanks in advance!

like image 922
Philip Daubmeier Avatar asked Jun 07 '11 13:06

Philip Daubmeier


People also ask

How do you overwrite an abstract method?

A non-abstract child class of an abstract parent class must override each of the abstract methods of its parent. A non-abstract child must override each abstract method inherited from its parent by defining a method with the same signature and same return type. Objects of the child class will include this method.

Can abstract method be overridden?

An abstract method is a method that is declared, but contains no implementation. you can override both abstract and normal methods inside an abstract class. only methods declared as final cannot be overridden.

Which method we Cannot be override abstract?

In Java, a static method cannot be abstract.

How do you override an abstract method in a subclass?

To implement features of an abstract class, we inherit subclasses from it and create objects of the subclass. A subclass must override all abstract methods of an abstract class. However, if the subclass is declared abstract, it's not mandatory to override abstract methods.


1 Answers

Basically, you are out of luck without altering the library. There may be a subclass of Sequence that does implement Copy, which you can derive from in the new version. But it is likely that the Copy method is need in other parts of the library to create clones.

like image 163
CodeNaked Avatar answered Sep 23 '22 06:09

CodeNaked