|
-
February 8th, 2008, 05:41 AM
#1
Preventing methods from being inherited
Hi everyone! As usual, I come to you with an almost absurd question.
I'm coding some classes for a MIDI application. As probably some of you know, the MIDI channel events (the most commonly used ones) are a string of three bytes, where the first byte determines what kind of message the event is. For example, 0x9n is a Note On on channel n, while 0x8n is a Note Off on that channel. Other bytes specify parameters.
What I would now want to do is to simplify message creation by defining a class for each kind of message. Like a class MIDINoteOn, a class MIDINoteOff, a class MIDIControlChange and so on. Since most of the functionality and of the status of these objects is common, I would define a base class MIDIChannelEvent from which the other would inherit. It would contain an array of three bytes (or a vector maybe, for safety reasons) and the necessary methods.
The problem is: the generic class could allow the user to specify what kind of message it should be (through a SetEventKind() method), so that a generic channel event can be a Note On or a Note Off or anything else, but the derived classes shouldn't (a Note On should always be just a Note On). In a sense, the very purpose of having one class per kind is exactly to let the user create a Note On without even knowing that it's almost the same as a Control Change.
But if I make the SetEventKind() method public in the base class, then the derived classes will inherit it (and it will be public). I thought of making the method reserved in the base class, but since I need the user of the class to access it I'd have to define a public "wrapper" for it, and this wrapper would be inherited as public. I also thought of making the inheritance private or protected (class MIDINoteOn : protected MIDIChannelEvent), but there's some functionality in the base class that needs to be public.
What would you suggest in order to have the method "not being inherited"? Thanks everyone!
I owe Paul McKenzie a pizza.
I am no expert; but they say I can make concepts easy to understand. That's why newbies questions are mine!!! XD
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|