Click here to Skip to main content
16,019,273 members
Home / Discussions / C#
   

C#

 
AnswerRe: Windows Service interaction with Sys Tray icon Pin
Eddy Vluggen12-Oct-12 5:45
professionalEddy Vluggen12-Oct-12 5:45 
GeneralRe: Windows Service interaction with Sys Tray icon Pin
JD8612-Oct-12 5:48
JD8612-Oct-12 5:48 
GeneralRe: Windows Service interaction with Sys Tray icon Pin
Dave Kreskowiak12-Oct-12 6:08
mveDave Kreskowiak12-Oct-12 6:08 
GeneralRe: Windows Service interaction with Sys Tray icon Pin
Eddy Vluggen12-Oct-12 10:57
professionalEddy Vluggen12-Oct-12 10:57 
GeneralRe: Windows Service interaction with Sys Tray icon Pin
JD8612-Oct-12 11:11
JD8612-Oct-12 11:11 
AnswerRe: Windows Service interaction with Sys Tray icon Pin
Eddy Vluggen12-Oct-12 13:33
professionalEddy Vluggen12-Oct-12 13:33 
QuestionRenaming tool project/class structure Pin
Adam_Dev12-Oct-12 4:46
Adam_Dev12-Oct-12 4:46 
AnswerRe: Renaming tool project/class structure Pin
Eddy Vluggen12-Oct-12 5:28
professionalEddy Vluggen12-Oct-12 5:28 
UCLAdam wrote:
Am I approaching this right with an abstract base class or should I be taking a different approach?

Nope, sounds about right.

UCLAdam wrote:
But I also just want to be able to call _profiles.CurrentProfile.Rename(...).

As long as the object implements the member with the name "Rename", that should work. Your main application would still be working with that base-class, calling methods on it. You could use a strategy-pattern to decide which derived class gets instantiated;
C#
namespace bla 
{
    abstract class DuckBase
    {
        abstract public void Rename();
    }
    class RubberDuck: DuckBase
    {
        // implementation 1
        override public void Rename()
        {
            Console.WriteLine("Squeek");
        }
    }
    class MallardDuck : DuckBase
    {
        // implementation 2
        public override void Rename()
        {
            Console.WriteLine("Quack");
        }
    }

    class Program
    {
        // These are the type of ducks we support. You could also use a string or 
        //  an int to identify them, just choose an enum for this example
        enum KindaDuck { RubberDuck, MallardDuck };

        // this is what's called a factory-method; it returns an actual implementation 
        //  of a "DuckBase"-object
        DuckBase DuckFactory(KindaDuck DuckType)
        {
            switch (DuckType)
            {
                case KindaDuck.MallardDuck: return new MallardDuck();
                case KindaDuck.RubberDuck: return new RubberDuck();
            }
            throw new IndexOutOfRangeException(DuckType.ToString() + " is not a known duck.");
        }

        static void Main(string[] args)
        {
            DuckBase ducky = new RubberDuck();
            ducky.Rename();
            Console.ReadKey(); 
        } 
    }
}

The only rule is that the Rename method must have the same signature everywhere. If that becomes a problem, call back again, as there's a simple solution Smile | :)
Bastard Programmer from Hell Suspicious | :suss:
if you can't read my code, try converting it here[^]

GeneralRe: Renaming tool project/class structure Pin
Adam_Dev14-Oct-12 22:13
Adam_Dev14-Oct-12 22:13 
GeneralRe: Renaming tool project/class structure Pin
Eddy Vluggen15-Oct-12 0:40
professionalEddy Vluggen15-Oct-12 0:40 
AnswerRe: Renaming tool project/class structure Pin
n.podbielski12-Oct-12 5:35
n.podbielski12-Oct-12 5:35 
QuestionHow to implement a resumable HTTP download? Pin
Jun Du12-Oct-12 3:48
Jun Du12-Oct-12 3:48 
AnswerRe: How to implement a resumable HTTP download? Pin
Eddy Vluggen12-Oct-12 5:07
professionalEddy Vluggen12-Oct-12 5:07 
QuestionHow to change color (combo,Text etc) when enable=false Pin
himmubhai12-Oct-12 3:09
himmubhai12-Oct-12 3:09 
GeneralRe: How to change color (combo,Text etc) when enable=false Pin
Marco Bertschi12-Oct-12 4:53
protectorMarco Bertschi12-Oct-12 4:53 
GeneralRe: How to change color (combo,Text etc) when enable=false Pin
himmubhai12-Oct-12 6:13
himmubhai12-Oct-12 6:13 
QuestionCan someone explain this... Pin
DanielSheets12-Oct-12 2:34
DanielSheets12-Oct-12 2:34 
AnswerRe: Can someone explain this... Pin
Eddy Vluggen12-Oct-12 2:38
professionalEddy Vluggen12-Oct-12 2:38 
GeneralRe: Can someone explain this... Pin
DanielSheets12-Oct-12 2:40
DanielSheets12-Oct-12 2:40 
GeneralRe: Can someone explain this... Pin
Eddy Vluggen12-Oct-12 2:51
professionalEddy Vluggen12-Oct-12 2:51 
GeneralRe: Can someone explain this... Pin
DanielSheets12-Oct-12 2:55
DanielSheets12-Oct-12 2:55 
GeneralRe: Can someone explain this... Pin
OriginalGriff12-Oct-12 3:52
mveOriginalGriff12-Oct-12 3:52 
GeneralRe: Can someone explain this... Pin
DanielSheets19-Oct-12 1:31
DanielSheets19-Oct-12 1:31 
GeneralRe: Can someone explain this... Pin
OriginalGriff19-Oct-12 1:35
mveOriginalGriff19-Oct-12 1:35 
GeneralRe: Can someone explain this... Pin
Bernhard Hiller12-Oct-12 3:14
Bernhard Hiller12-Oct-12 3:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.