Reputation: 16662
I have the following chicken/egg inheritance problem:
Here, base classes I can derive from, but they're on a framework, thus, I can't modify them:
class Editor
{
}
class ScriptedImporterEditor : Editor
{
}
Here, are classes in my project:
An editor with a preview, this works as expected, Cylinder
and Torus
have DrawPreview
:
class EditorWithPreview : Editor
{
public void DrawPreview(){}
}
class Cylinder : EditorWithPreview
{
// DrawPreview is available
}
class Torus : EditorWithPreview
{
// DrawPreview is available
}
But now I need a scripted importer editor that can also preview:
class ScriptedImporterEditorWithPreview : ScriptedImporterEditor
{
// cannot inherit EditorWithPreview as it's not a ScriptedImporterEditor
}
class Cube : ScriptedImporterEditorWithPreview
{
// unable to use DrawPreview
}
class Sphere : ScriptedImporterEditorWithPreview
{
// unable to use DrawPreview
}
So basically,
Editor
nor ScriptedImporterEditor
as I don't own themEditorWithPreview
to ScriptedImporterEditor
Cube
and Sphere
can't inherit and use DrawPreview
Upvotes: 0
Views: 55
Reputation: 17485
Following may help.
class ScriptedImporterEditorWithPreview : ScriptedImporterEditor
{
private EditorWithPreview editorWithPreview = null;
public ScriptedImporterEditorWithPreview(EditorWithPreview editorWithPreview)
{
this.editorWithPreview = editorWithPreview;
}
public virtual void DrawPreview() // based on need it is virtual or non-virtual
{
this.editorWithPreview.DrawPreview();
}
}
class Cube : ScriptedImporterEditorWithPreview
{
}
class Sphere : ScriptedImporterEditorWithPreview
{
}
Upvotes: 1