Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
Medium Priority
?
261 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 500 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 500 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

636 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