Exercise: Cloud Resource Management
Problem statement
A cloud platform categorizes its infrastructure using hierarchical contracts. A scalable virtual machine must satisfy the requirements of a basic resource, a computable resource, and a scalable resource. Implement this interface hierarchy and satisfy the entire chain within a single concrete class.
Task requirements
Define a three-level interface inheritance chain:
IResource,IComputableResource, andIScalableResource.Create a
VirtualMachineclass that implements the most derived interface in the chain.Provide concrete behaviors for all capabilities inherited throughout the contract chain.
Ensure your implementation works with the provided
Program.cslogic.
Constraints
IComputableResourcemust inherit fromIResource, andIScalableResourcemust inherit fromIComputableResource.VirtualMachinemust explicitly declare implementation of only theIScalableResourceinterface.The implementations for
Start,AssignTask, andScaleUpmust output exactly"Virtual machine booting up...","Task assigned to virtual machine.", and"Allocating additional CPU and RAM...", respectively.You must place all types in the
CloudPlatformfile-scoped namespace.
Good luck trying the exercise! If you’re unsure how to proceed, check the “Solution” tab above.
Get hints
Use the colon
:syntax on an interface definition to inherit from another interface.When a class implements a derived interface, it is required to implement all methods from the parent interfaces as well.
You do not need to explicitly list the parent interfaces on the class declaration, because listing the most derived interface (
IScalableResource) is sufficient.
Exercise: Cloud Resource Management
Problem statement
A cloud platform categorizes its infrastructure using hierarchical contracts. A scalable virtual machine must satisfy the requirements of a basic resource, a computable resource, and a scalable resource. Implement this interface hierarchy and satisfy the entire chain within a single concrete class.
Task requirements
Define a three-level interface inheritance chain:
IResource,IComputableResource, andIScalableResource.Create a
VirtualMachineclass that implements the most derived interface in the chain.Provide concrete behaviors for all capabilities inherited throughout the contract chain.
Ensure your implementation works with the provided
Program.cslogic.
Constraints
IComputableResourcemust inherit fromIResource, andIScalableResourcemust inherit fromIComputableResource.VirtualMachinemust explicitly declare implementation of only theIScalableResourceinterface.The implementations for
Start,AssignTask, andScaleUpmust output exactly"Virtual machine booting up...","Task assigned to virtual machine.", and"Allocating additional CPU and RAM...", respectively.You must place all types in the
CloudPlatformfile-scoped namespace.
Good luck trying the exercise! If you’re unsure how to proceed, check the “Solution” tab above.
Get hints
Use the colon
:syntax on an interface definition to inherit from another interface.When a class implements a derived interface, it is required to implement all methods from the parent interfaces as well.
You do not need to explicitly list the parent interfaces on the class declaration, because listing the most derived interface (
IScalableResource) is sufficient.