You work as the Enterprise application developer at Domain.com. The Domain.com network consists of a single Active Directory domain named Domain.com. All servers in the domain run Windows Server 2003. Your responsibilities at Domain.com include the design and development of applications. Domain.com operates as a service provider in the security industry. You are currently developing a video surveillance application for Domain.com. You need to implement a class named Visuals. Visuals will be destined to control access to a video camera. A method named CommenceRecording must start a recording session of the camera if one is not already started. In the event of a recording session having started already when the method is called, you have to interrupt the execution of the application. To this end you now need to define the Visuals class.
What should you do? (Choose the correct code segment.)
A.
Public Class Visuals
Private _recording As Boolean = False
Public Sub CommenceRecording()
If (_recording = True) Then
MessageBox.Show(“A recording session is in progress.”)
End If
‘Start recording
_recording = True
End Sub
End Class
B.
Public Class Visuals
Private _recording As Boolean = False
Public Event Recording As EventHandler
Public Sub CommenceRecording()
If (_recording = True)
RaiseEvent Recording(Me, EventArgs.Empty)
End If
‘Start recording
_recording = True
End Sub
End Class
C.
Public Class Visuals
Private _recording As Boolean = False
Private Sub CommenceRecording()
If (_recording = True) Then
Throw New InvalidOperationException(“A recording session is in progress.”)
End If
‘Start recording
_recording = True
End Sub
End Class
D.
Public Delegate Sub RecordingStarted(ByVal message As String) Public Class Visuals
Private _recording As Boolean = False
Public Recording As RecordingStarted
Public Sub CommenceRecording()
If (_recording = True) Then
Recording(“A recording session is in progress.”)
End If
‘Start Recording
_recording = True
End Sub
End Class
Explanation:
If the method is called when there is already a recording session in progress then you should throw an exception. This will allow you to interrupt the normal flow of an application.
Incorrect answers:
A: Displaying a message box does not interrupt the execution of an application; it would instead result in an interruption to the user.
B: Raising an event will result in the application to subscribe to the event to receive notification regarding the status of recording sessions. Thus it will not interrupt the execution of the application.
D: Invoking a delegate is not the solution since it will result in the application to require associating with a method with the delegate to receive notification regarding recording session status and as such would not interrupt the execution of the application.