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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to remove double quotes from a string in VB.Net 5 47
vb.net checkbox 7 46
VB.net and sql server 4 33
vb.net and creating a class 5 14
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

815 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

10 Experts available now in Live!

Get 1:1 Help Now