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
246 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

706 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

18 Experts available now in Live!

Get 1:1 Help Now