Michael Riva
Michael Riva

Reputation: 541

What kinds of types may an interface type include?

I have some class type:

class MyClass
{
    …
}

I wonder whether it is good or bad design to include this type of object in an interface:

interface IInterface
{
   List<MyClass> _myobj { get; set; }
}

Is it bad practice? Does this mean IInterface depends on MyClass because I am referencing it from this type?

Upvotes: 2

Views: 100

Answers (1)

BradleyDotNET
BradleyDotNET

Reputation: 61379

Is it bad practice? NO. You will do this all the time.

Yes, it makes the interface "dependent" on that type, but there is no problem with that. If you need it in the interface, you have a really good chance that they should be dependent.

For me, your code is perfectly fine, I wouldn't change a thing except for the weird naming on the property. Properties in C# start with a capital letter, and are camel case from there (otherwise known as PascalCase).

Upvotes: 6

Related Questions