Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have a lot of services, some that demand some security, some that don't. We want an easy way of telling, in code, if a service will be secure or not.

What would be the better way: Annotation or inheritance?

public class SomeServiceImplementation : BaseSecureService, ISomeService


public class SomeServiceImplementaion : ISomeService
share|improve this question

Use annotations

Security is generally considered a cross-cutting concern so an inheritance path is generally unsuitable for this purpose.

share|improve this answer

As you said marking services. in the question the answer is annotations / attributes.

C# attributes can be placed on entities in your source code to specify additional information.

This seems to fit what you need.

If each entity were required to provide certain functions to participate in the security then it would be best to use an interface.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.