Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make interface extend class

I have the following situation, but I feel like I'm doing something wrong... enter image description here

I used a interface for Field according to this post. The Field interface inherits from the Style class and Field1, 2 and 3 inherit from the Field interface. I want to construct a Label object with a couple of different types of fields which each have their own styling. I'm not sure if I'm doing it the right way like this, especially because I get the following error when I try to compile: Type 'Style' in interface list is not an interface

My code:

public interface Field : Style
{
    int Xpos { get; set; }
    int Ypos { get; set; }
    int Zindex { get; set; }
}

What is the best way to solve this?

EDIT

I know inheriting a class from an interface is impossible, but what would be the best approach here?

like image 412
Markinson Avatar asked Oct 24 '25 19:10

Markinson


1 Answers

Find/Create an interface that is utilized by Style and inherit that interface on the field interface.

Note, field interface should be named IField.

If Style is your own class

public interface IStyle
{
    /* Style properties */
}
public class Style : IStyle
{
    /* Style implementations */
}

public interface IField : IStyle
{
    int Xpos { get; set; }
    int Ypos { get; set; }
    int Zindex { get; set; }
}

public class Field : Style, IField
{
    public int Xpos { get; set; }
    public int Ypos { get; set; }
    public int Zindex { get; set; }
}
like image 115
Paul Tsai Avatar answered Oct 26 '25 08:10

Paul Tsai