Bird
0
0

You need to design a plugin system where multiple unrelated classes must provide a Run() method. Which approach is best and why?

hard🚀 Application Q8 of 15
C Sharp (C#) - Interfaces
You need to design a plugin system where multiple unrelated classes must provide a Run() method. Which approach is best and why?
AUse an abstract class with Run() method to share common code among plugins.
BUse a concrete base class with Run() method to allow direct instantiation.
CUse an interface with Run() method to enforce the contract across unrelated classes.
DUse static classes with Run() methods for all plugins.
Step-by-Step Solution
Solution:
  1. Step 1: Identify requirement for unrelated classes

    Unrelated classes cannot share a common base class easily, so interface suits better.
  2. Step 2: Evaluate options

    Interface enforces Run() method without forcing inheritance, ideal for plugins.
  3. Final Answer:

    Use an interface with Run() method to enforce the contract across unrelated classes. -> Option C
  4. Quick Check:

    Interface suits unrelated classes needing common methods [OK]
Quick Trick: Use interface to enforce methods on unrelated classes [OK]
Common Mistakes:
MISTAKES
  • Choosing abstract class for unrelated classes
  • Using concrete base class limiting inheritance
  • Misusing static classes for instance behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes