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 6350839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:53:16+00:00 2026-05-24T21:53:16+00:00

I was ready up on Ruby’s method of enforcing interfaces w/ dynamic typing by

  • 0

I was ready up on Ruby’s method of enforcing interfaces w/ dynamic typing by checking for the existence of methods/properties that satisfy an interface.

In what ways is this overall just a better design principle than using interfaces? What are the pros/cons. For example you could implement the same concept in C# but I’m not sure if it would have the same value,

public class Foo
{
   public Foo(dynamic _obj)
   {
        MethodInfo[] methods= _obj.GetType().GetMethods();

        if (!methods.Any(x => x.Name == "SomeRequiredMethod")
        {
            throw new ArgumentException("Object does not meet interface requirements.");
        }
   }

   // proceed with functionality that requires the method
}

And of course you could extend this to check more than just the name, like the signature, return type, etc.

Thoughts?

  • 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-24T21:53:17+00:00Added an answer on May 24, 2026 at 9:53 pm

    I can see several major issues problems with this approach:

    1. reflection is slow
    2. dynamic calls are also much slower than strongly-typed calls
    3. the code is more complicated

    And I can’t see any advantage, except perhaps for very specific needs…

    C# was designed as a static, strongly-typed language, and even though it now has some dynamic capabilities, they should only be used when there is no strongly-typed alternative.

    If you really need to use the object dynamically, don’t check the members manually: instead, put the code in a try block, and catch the RuntimeBinderException that will occur if a member you call is missing.

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

Sidebar

Related Questions

The standard Ruby library io/wait provides a method on IO objects ready? that returns
I was wondering if there is a similar .finalize() method for Ruby objects, that
Is there a solid, production ready library in Ruby that interacts with the Flickr
I read on another Stack Overflow question that Python was just like Ruby, as
I read from some books that Phusion Passenger is the answer to easy Ruby
is the ruby mysqlplus adapter production ready? have a choice between: 1. mysql library
I'm looking to build a web interface for an existing Ruby app and I'm
Is there any production ready open source twitter clones written in Ruby or Python
I'm looking for a method in Ruby which is basically this: io.ready_for_read? I just
View JavaScript: $(document).ready(function() { $(input#autocomplete).autocomplete({ source: [c++, java, php, coldfusion, javascript, asp, ruby] });

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.