Solved

when do you use mustoverride in what kind of situations. I need a good example to understand the feature.

Posted on 2011-03-14
5
250 Views
Last Modified: 2013-11-05
when do you use mustoverride in what kind of situations. I need a good example to understand the feature.
0
Comment
Question by:Jsara
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
murphomatic earned 125 total points
ID: 35131872
A good example would be a situation where you're creating a base class, but all the inheriting classes will need to implement their own functionality for a particular method.  

Let's say you're creating a base class called "Vehicle," which contains a MustOverride method called "Drive".  You'll be creating several classes that inherit from vehicle - such as "Boat," "Truck," "Tank," ...etc ...  All are vehicles, but each have a very different implementation of "Drive."

You could do this with an interface/abstract class - but in that case, ALL of the methods in the interface would be essentially MustOverride.  If you create a base class for Vehicle - you can write implementation code for other various parts, and then have "Drive" be the only method you declare as MustOverride, requiring each child class to implement its own version of "Drive."

Hope this helps!
0
 
LVL 1

Assisted Solution

by:pjbaratelli
pjbaratelli earned 125 total points
ID: 35132098
Just to expand this section:


Let's say you're creating a base class called "Vehicle," which contains a MustOverride method called "Drive".  You'll be creating several classes that inherit from vehicle - such as "Boat," "Truck," "Tank," ...etc ...  All are vehicles, but each have a very different implementation of "Drive."

Changing MustOverride method from  "Drive" to "Move"

When you use the Vehicle bass class containing MustOverride, the other classes that would inherit this class would have to have the method "Move" in it.  The method would control how each type of Vehicle Moves.  

A boat moves only on water, so logic would be placed to determine movement in water.  
A car drives on roads (mostly), so logic would be placed to determine movement on a road.
A truck drices on roads and off roads, so logic would be placed to determine move on and off a road

etc........

To conclude, you use "MustOverride" in the above example because all vehicles Move differently and it forces each vehicle to Move in some way shape or form.  




0
 

Author Comment

by:Jsara
ID: 35142386
thanks. It helps.
0
 
LVL 2

Expert Comment

by:murphomatic
ID: 35142401
To be fair - while pjbaratelli's comment added clarification, ultimately it is my answer that deserves the points awarded for this question.  Can you please assign the points appropriately?

Thanks -
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual Studio .Net 2012 and Crystal Reports 9 43
Visual Studio 2013 Shortcut (VB) 4 33
Help with Query not working in client's PC 1 35
Help with AsEnumerable(), LINQ 4 19
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now