Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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

or

[SecureService]
public class SomeServiceImplementaion : ISomeService
share|improve this question
add comment

2 Answers 2

Use annotations

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

share|improve this answer
add comment

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
add comment

Your Answer

 
discard

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.