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
254 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 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