vgoof / csharptrainingAlten

C sharp training
0 stars 0 forks source link

Do not understand instructions of OOP training mod 3 self assessment #1

Open vgoof opened 6 years ago

vgoof commented 6 years ago

The course instructs the following:

_"In module 2, you created a set of classes with inheritance as a consideration. In this lab you will apply your knowledge of inheritance and the concepts in this module to create one final lab application.

The tutorial lab showed you how to make use of the StreamReader object for working with a text file. The shot scenario for this lab is that you want to write out the information relevant to your Student and Teacher objects to a text file. Because the text file is an unmanaged resource, you want to ensure that you classes make proper use of memory management and object lifetime considerations.

For this lab, use the same class hierarchy you created in the lab in Module 2. You need to accomplish the following to be successful in this lab and to answer the assessment questions at the end:

Choose the proper class in the hierarchy that will implement the IDisposable interface Implement the IDisposable interface in that class. Refer back to the text content and use msdn.microsoft.com to research IDisposable for code samples if you are still not clear on how to implement it. Ensure that you class has a destructor Ensure that in your destructor you check for the existence of the proper object Call the appropriate methods, in the proper locations, to close your file before your object is destroyed. Ensure that you have used the dispose method for the StreamReader object Signal to the .NET runtime that your application is ready for resource management by calling the proper method on the correct object. Note that the object and method are not named here but are left up to you to determine the proper options. Run your code and ensure it compiles and runs correctly."_

But I do not get the point, all of these objects are managed objects and the streamreader objects are inside a using block. (see mod3_selfasses)

So where should I implement the IDisposable interface?

vgoof commented 6 years ago

https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-dispose

janssenMA commented 6 years ago

Is this still open?

vgoof commented 6 years ago

Yes

janssenMA commented 6 years ago

The exercise can be done with just a 'using()'. However, the assignment here is to understand how the IDisposable interface should be implemented.

So: