Home > Net >  Implementing only specific Interfaces from a lista when creating an object?
Implementing only specific Interfaces from a lista when creating an object?

Time:10-26

I have the Class Word and this class can implements noun, adjective, adverbs, etc. These interfaces extend another major Interface too.

But there are a lot of combinations that this class Word can have. For example, a word could be a noun only or a noun and an adjective.

How can I initialize this object using a list of Interface that must be implemented when it is created?

I want to create the Word Act as example. It could be sometimes verb, sometimes noun. How can I before instantiate the object, put the interfaces Noun and Verb to be implemented only in this specifically class Word?

CodePudding user response:

An instance of a given class must always implement the same set of interfaces; you cannot customize which interfaces are implemented on a per-object basis.

Instead, you will have to solve this with data: having e.g. a boolean isVerb field, or a Set<PartOfSpeech> reflecting which apply.

  • Related