Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7748369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:46:02+00:00 2026-06-01T10:46:02+00:00

I’m doing a multiplatform thing, but I’m not very good with OOP. Currently my

  • 0

I’m doing a multiplatform thing, but I’m not very good with OOP. Currently my code is:

    public interface IMessageBox {
        void Show(string Text);
        void Show(string Text, string Description, MessageBoxType Type);
        MessageBoxResult ShowYesNo(string Text, string Description, MessageBoxType Type);
        MessageBoxResult ShowYesNoCancel(string Text, string Description, MessageBoxType Type);
    }

    public class MessageBox : InstanceGenerator {
        public static void Show(string Text) {
            MessageBoxImpl.Show(Text);
        }

        public static void Show(string Text, string Description, MessageBoxType Type) {
            MessageBoxImpl.Show(Text, Description, Type);
        }
        public static MessageBoxResult ShowYesNo(string Text, string Description, MessageBoxType Type) {
            return MessageBoxImpl.ShowYesNo(Text, Description, Type);
        }
        public static MessageBoxResult ShowYesNoCancel(string Text, string Description, MessageBoxType Type) {
            return MessageBoxImpl.ShowYesNoCancel(Text, Description, Type);
        }
    }

protected class InstanceGenerator {
        public static IMessageBox MessageBoxImpl = null;
        public static IWindow WindowImpl = null;

        private static Assembly Instance = null;
        private static string InstanceName = null;

        private static Assembly LoadAssembly(string lib) {
            string AppPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            Assembly assembly = Assembly.LoadFile(Path.Combine(AppPath, lib + ".dll"));
            return assembly;
        }

        private static object CreateInstance(string @class) {
            Type type = Instance.GetType(InstanceName + "." + @class);
            return Activator.CreateInstance(type);
        }

        private static object CreateInstanceFromPath(string lib, string @class) {
            string AppPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            Assembly assembly = Assembly.LoadFile(Path.Combine(AppPath, lib + ".dll"));
            Type type = assembly.GetType(lib + "." + @class);
            return Activator.CreateInstance(type);
        }


        /// <summary>
        /// Inits the whole thing
        /// </summary>
        public static void Init() {
            if (CurrentOS.IsWindows)
                InstanceName = "Lib.Windows";
            else if (CurrentOS.IsMac)
                InstanceName = "Lib.MacOS";
            else if (CurrentOS.IsLinux)
                InstanceName = "Lib.Linux";
            else // no implementation for other OSes
                throw new Exception("No implementation of Lib for this OS");

            Instance = LoadAssembly(InstanceName);

            // initialize the classes
            MessageBoxImpl = (IMessageBox) CreateInstance("MessageBox");
        }
    }

EDIT:

Where InstanceGenerator returns an instance of the IMessageBox loaded from an assembly. Is there a better way to create/connect to an instance? Implementing all the same static methods looks not good soltution at all. Is there a more automatic way to wrap those interfaces with a class or I’m doing something wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:46:04+00:00Added an answer on June 1, 2026 at 10:46 am

    You’re not currently implementing the interface. You can’t use static methods to implement an interface. You have to use instance methods. You can call static methods within the implementation, of course, but that’s a different matter.

    It doesn’t sound like MessageBox should derive from InstanceGenerator – I’d suggest that it should compose it:

    public class MessageBox : IMessageBox {
    
        private readonly InstanceGenerator generator;
    
        public MessageBox(InstanceGenerator generator) {
            this.generator = generator;
        }
    
        public static void Show(string Text) {
            generator.MessageBoxImpl.Show(Text);
        }
    
        public static void Show(string text, string description, MessageBoxType type) {
            generator.MessageBoxImpl.Show(text, description, type);
        }
    
        public static MessageBoxResult ShowYesNo(string text, string description, 
                                                 MessageBoxType type) {
            return generator.MessageBoxImpl.ShowYesNo(text, description, type);
        }
    
        public static MessageBoxResult ShowYesNoCancel(string text,
                                                       string description,
                                                       MessageBoxType type) {
            return generator.MessageBoxImpl.ShowYesNoCancel(text, description, type);
        }
    }
    

    I’m assuming that MessageBoxImpl doesn’t already implement IMessageBox as otherwise all of this is pretty pointless…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.