Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Static Members derived from Interface Class

Static Members derived from Interface Class

Scheduled Pinned Locked Moved C#
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LiamD
    wrote on last edited by
    #1

    I have a program that consists of a number of messages type. I am trying to ensure that all messages of a given type have a dedicated handler. Each message type has its own message handler. I have created an interface base class which states all messages need a handler. Each derived class should have a single event handler, therefore I used the static keyword so that it is common across all the derived classes i.e. a single handleMsg for all instances of the msg1 class. So I implemented this: interface baseMsg { void handleMsg (); } class msg1 : baseMsg { … public static void handleMsg () { Console.WriteLine ("msg1 Handled"); } } class msg2 : baseMsg { … public static void handleMsg () { Console.WriteLine ("msg2 Handled"); } } I am getting an error CS0536: Error Message 'class' does not implement interface member 'interface member'. 'class member' is static, not public, or has the wrong return type So I cannot implement it in the way I originally thought. Does anyone have any suggestion on how I can achieve this? Thanks, LiamD

    E 1 Reply Last reply
    0
    • L LiamD

      I have a program that consists of a number of messages type. I am trying to ensure that all messages of a given type have a dedicated handler. Each message type has its own message handler. I have created an interface base class which states all messages need a handler. Each derived class should have a single event handler, therefore I used the static keyword so that it is common across all the derived classes i.e. a single handleMsg for all instances of the msg1 class. So I implemented this: interface baseMsg { void handleMsg (); } class msg1 : baseMsg { … public static void handleMsg () { Console.WriteLine ("msg1 Handled"); } } class msg2 : baseMsg { … public static void handleMsg () { Console.WriteLine ("msg2 Handled"); } } I am getting an error CS0536: Error Message 'class' does not implement interface member 'interface member'. 'class member' is static, not public, or has the wrong return type So I cannot implement it in the way I originally thought. Does anyone have any suggestion on how I can achieve this? Thanks, LiamD

      E Offline
      E Offline
      Ed Poore
      wrote on last edited by
      #2

      A singleton pattern for the event-handler class?


      Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9 Ed

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups