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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:44:41+00:00 2026-06-03T10:44:41+00:00

I was reading Dart’s documentation and I was a little bit confused, maybe because

  • 0

I was reading Dart’s documentation and I was a little bit confused, maybe because I’m coming from Ruby, as to how to use interfaces. Of course, interfaces are not unique to Dart and there are quite a number of explanations out there on when one should use an interface. This one, for example, seems to be saying that interfaces are only useful when you’re in a team. What is it even supposed to mean in the open source world, where everybody reads and reuses somebody else’s code?

One interesting explanation I’ve seen seemed to be implying that interfaces are used:

  1. in languages that lack multiple inheritance, and
  2. for that matter they somehow serve as a workaround for the absence of multiple inheritance.

I don’t understand that. I understand that modules in Ruby are a workaround because they allow me to define real methods with actual bodies. Interfaces only allow me to define what methods a class implementing it should have. What’s the catch? Can anyone tell of a real useful example where I can immediately see the value of using interfaces?

P.S. On a related note, is there a way to use multiple inheritance in Dart?

  • 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-03T10:44:55+00:00Added an answer on June 3, 2026 at 10:44 am

    Update: the interface keyword has since been removed from Dart.


    Interfaces are useful because they allow you to switch implementations of a class, whilst still allowing validation that the type being passed in meets the requirements of the interface.

    Take the following (often used) example:

    interface Quackable {
      void quack();
    }
    

    This defines the requirements of a class that will be passed to a method such as:

    sayQuack(Quackable quackable) {
       quackable.quack();
    }
    

    which allows you to make use of any implementation of a Quackable object, such as:

    class MockDuck implements Quackable {
      void quack() => print("quack");
    }
    
    class EnterpriseDuck implements Quackable {
      void quack() {
        // connect to three enterprise "ponds"
        // and eat some server bread
        // and say "quack" using an messaging system
      }
    
    }
    

    Both of these implementations will work with the sayQuack() function, but one requires significantly less infrastructure than the other.

    sayQuack(new EnterpriseDuck());
    sayQuack(new MockDuck());
    

    I use this pattern all the time in the Java world, when building solutions that make use of some “enterprise duck”. When developing locally, all I simply need is to be able to call the sayQuack() function and return some hard-coded, mock data.

    Duck typing

    Because Dart is optionally typed, you don’t actually need to use the interface, simply writing a class that contains the correct method signature will work (although the tools won’t be able to validate it).

    class Person {   // note: no implements keyword
      void quack() => "I'm not a duck";
    }
    
    sayQuack(new Person()); // provides the quack method, so this will still work
    

    All classes are interfaces

    Finally, all Classes are also interfaces. This means that even though a third party system may have been written without using interfaces, you can still use a concrete class as though it were an interface.

    For example, imagine the following enterprise library:

    class EnterpriseDuck { // note: no implements keyword
      void quack() {
        // snip
      }
    }
    
    sayQuack(EnterpriseDuck duck) {  // takes an instance of the EnterpriseDuck class
      duck.quack();
    }
    

    And you want to pass a mock duck into the sayQuack method in a way that the type checker can validate. You can create your mockDuck to implement the interface implied by EnterpriseDuck, simply by using the EnterpriseDuck as an interface:

    class MockDuck implements EnterpriseDuck {
      void quack() => "I'm a mock enterprise duck";
    }
    

    Multiple Inheritance

    In terms of multiple inheritance, this is not possible in Dart. You can, however, implement multiple interfaces and provide your own implementations of the required methods, eg:

    class MultiDuck implements Quackable, EnterpriseDuck, Swimable {
      // snip...
    }
    

    Interfaces can have default classes

    As you use Dart, you will find that most “classes” are actually interfaces. List, String etc… are all interfaces with default implementations provided. When you call

    List myList = new List();
    

    you are actually using a List interface, and the new keyword redirects from the interface to an underlying default List implementation.

    With regards to developing in a team

    Interfaces are useful in team development, even in the open source world. The interface defines the methods and properties that you should be building so that your component works with my component. You can build your own test implementation of that interface, and I can build my concrete implementation of that interface, and when we’re both done, we can integrate. Without the published, shared interface, I would need to provide my concrete implementation before you could really get started.

    Hope that helps!

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

Sidebar

Related Questions

reading this https://developers.google.com/in-app-payments/docs/tutorial Quoted from the above page: Because you sign the JWT using
reading excel files from C# working well in 32 bit version server. It is
Reading the documentation for the spawn gem it states: By default, spawn will use
Reading about the Dispose pattern , I see the documentation repeatedly refer to cleaning
reading the documentation for java org.w3c.dom.ls it seems as a Element only can be
Reading some posts from Jimmy Boggard and wondering - how exactly is it possible
Reading Kohana's documentation, I found out that the main difference in 3.0 version is
Reading code from other posts, I'm seeing something like this. struct Foo { Foo()
Reading through the CKEditor documentation , I see that they have an option to
Reading MSDN, float ranges from 1E-45 to 1E38, double ranges from 1E-324 to 1E308,

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.