Exercise: Confidential Documents
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
IPrintableandIEncryptableinterfaces that both declare aProcessmethod.Create a
TopSecretBriefingclass 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
Processmethods to hide them from the class's default public scope and resolve the naming collision.IPrintable.Processmust output exactly"Printing physical copy..."andIEncryptable.Processmust output exactly"Encrypting digital file...".In
Program.cs, you must cast theTopSecretBriefinginstance to each respective interface type before you can invoke theProcessmethods.You must place all types in the
Securityfile-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
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
IPrintableandIEncryptableinterfaces that both declare aProcessmethod.Create a
TopSecretBriefingclass 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
Processmethods to hide them from the class's default public scope and resolve the naming collision.IPrintable.Processmust output exactly"Printing physical copy..."andIEncryptable.Processmust output exactly"Encrypting digital file...".In
Program.cs, you must cast theTopSecretBriefinginstance to each respective interface type before you can invoke theProcessmethods.You must place all types in the
Securityfile-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()).