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

  • Home
  • SEARCH
  • 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 7367891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:35:40+00:00 2026-05-29T03:35:40+00:00

I am working on creating an IronPython console similar to the IronPythonConsole project provided

  • 0

I am working on creating an IronPython console similar to the IronPythonConsole project provided with the IronPython source code. However, I want to make the ConsoleHost more extensible than the sample provided, such that it could be extended to run an IronPython interpreter in XNA, or WPF etc. As such, I have created a class IronPythonConsoleHost that extends ConsoleHost (from Microsoft.Scripting.Hosting.Shell), modelled on the PythonConsoleHost source.

public class IronPythonConsoleHost : ConsoleHost
{
    ...
    public override IConsole CreateConsole(ScriptEngine engine, CommandLine commandLine, ConsoleOptions options)
    {
        return new IronPythonConsole();
    }
    ...
}

// run in a ConsoleApplication
static void Main(string[] args)
{
    new IronPythonConsoleHost().Run(args);
}

This creates a situation where IronPythonConsoleHost can be extended in other applications. For instance, a console could be integrated into XNA as follows (assuming appropriate supporting classes):

public class XnaConsoleHost : IronPythonConsoleHost
{
    public override IConsole CreateConsole(ScriptEngine engine, CommandLine commandLine, ConsoleOptions options)
    {
        return new XnaConsole();
    }
}

However, this creates a situation where I am inheriting IronPythonConsoleHost simply to override a single method – no other functionality of the class needs to be changed. Furthermore, XnaConsoleHost is not being used in any situation that expects an IronPythonConsoleHost (or indeed a ConsoleHost), and this would seem to go against the Liskov substitution principle, as there is no usage scenario where substitutability is required or appropriate.

It seems it would be more appropriate to design IronPythonConsoleHost such that it can be provided with a means of selecting what IConsole to create (i.e. using composition instead of inheritance):

public class IronPythonConsoleHost : ConsoleHost
{
    public IronPythonConsoleHost(Func<ScriptEngine, CommandLine, ConsoleOptions, IConsole> consoleSelector)
    {
        _consoleSelector = consoleSelector;
    }
    ...
    public override IConsole CreateConsole(ScriptEngine engine, CommandLine commandLine, ConsoleOptions options)
    {
        return _consoleSelector(engine, commandLine, options);
    }
    ...
}

This would allow the XNA game to simply construct an IronPythonConsoleHost with the appropriate selector function:

_console = new IronPythonConsoleHost((eng, cl, co) => new XnaConsole());

This approach works, but passing Funcs seems somewhat clunky. This definitely seems like a situation where inheritance is a much less robust solution, but I don’t think composition via awkward Funcs is necessarily better (especially if selectors are required for other areas – as they probably will be).

Is composition a good approach for this situation, and if so, are Funcs appropriate? Or is there a common design pattern that is used in similar situations that I am perhaps missing?

  • 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-05-29T03:35:41+00:00Added an answer on May 29, 2026 at 3:35 am

    Passing a Func as a factory method seems reasonable to me – but you may want to overload your constructor to accept a simpler form:

    public class IronPythonConsoleHost : ConsoleHost
    {
        // Full version
        public IronPythonConsoleHost(
           Func<ScriptEngine, CommandLine, ConsoleOptions, IConsole> consoleSelector)
        {
            _consoleSelector = consoleSelector;
        }
    
        public IronPythonConsoleHost(Func<IConsole> consoleSelector)
            this((engine, commandLine, options) => consoleSelector())
        {
        }
    
        ...
        public override IConsole CreateConsole(ScriptEngine engine,
            CommandLine commandLine, ConsoleOptions options)
        {
            return _consoleSelector(engine, commandLine, options);
        }
        ...
    }
    

    So you could then write:

    _console = new IronPythonConsoleHost(() => new XnaConsole());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on creating a new C# project that needs to interact with
I've been working on creating a simple IRC bot, which I want to give
I'm working on creating an ASCII interface for a school project but I've run
I am working on creating a daemon in Ruby using the daemons gem. I
I am working on creating a tag cloud in Silverlight 2 and trying to
I am working on creating an immutable class. I have marked all the properties
I'm working on creating a domain layer in Zend Framework that is separate from
I am working on creating a .asmx webservice to meet the specific needs of
I'm working on creating a call back function for an ASP.NET cache item removal
I'm working on creating a self updating application and one issue I'm running into

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.