Exercise: Confidential Documents

Resolve naming collisions using explicit interface implementation for secure document processing.

Problem statement

A secure data system processes sensitive documents using distinct protocols for physical printing and digital encryption. Both protocols require a generic Process() command, creating a naming collision. Implement both protocols on a single document class securely.

Task requirements

  • Define IPrintable and IEncryptable interfaces that both declare a Process method.

  • Create a TopSecretBriefing class that implements both interfaces and provides distinct logic for printing and encrypting.

  • In Program.cs, cast the instantiated class and execute both processes sequentially.

Constraints

  • You must use explicit interface implementation for both Process methods to hide them from the class's default public scope and resolve the naming collision.

  • IPrintable.Process must output exactly "Printing physical copy..." and IEncryptable.Process must output exactly "Encrypting digital file...".

  • In Program.cs, you must cast the TopSecretBriefing instance to each respective interface type before you can invoke the Process methods.

  • You must place all types in the Security file-scoped namespace.

Good luck trying the exercise! If you’re unsure how to proceed, check the “Solution” tab above.

Get hints

  • Explicit implementations do not use access modifiers like public.

  • The syntax for explicit implementation prefixes the interface name to the method name (e.g., void IMyInterface.MyMethod()).

Exercise: Confidential Documents

Resolve naming collisions using explicit interface implementation for secure document processing.

Problem statement

A secure data system processes sensitive documents using distinct protocols for physical printing and digital encryption. Both protocols require a generic Process() command, creating a naming collision. Implement both protocols on a single document class securely.

Task requirements

  • Define IPrintable and IEncryptable interfaces that both declare a Process method.

  • Create a TopSecretBriefing class that implements both interfaces and provides distinct logic for printing and encrypting.

  • In Program.cs, cast the instantiated class and execute both processes sequentially.

Constraints

  • You must use explicit interface implementation for both Process methods to hide them from the class's default public scope and resolve the naming collision.

  • IPrintable.Process must output exactly "Printing physical copy..." and IEncryptable.Process must output exactly "Encrypting digital file...".

  • In Program.cs, you must cast the TopSecretBriefing instance to each respective interface type before you can invoke the Process methods.

  • You must place all types in the Security file-scoped namespace.

Good luck trying the exercise! If you’re unsure how to proceed, check the “Solution” tab above.

Get hints

  • Explicit implementations do not use access modifiers like public.

  • The syntax for explicit implementation prefixes the interface name to the method name (e.g., void IMyInterface.MyMethod()).

C# 14.0
namespace Security;
public interface IPrintable
{
void Process();
}
public interface IEncryptable
{
void Process();
}
// TODO: Define the TopSecretBriefing class that implements both interfaces
// TODO: Implement IPrintable.Process explicitly
// TODO: Implement IEncryptable.Process explicitly