in Education by
Could someone please demystify interfaces for me or point me to some good examples? I keep seeing interfaces popup here and there, but I haven't ever really been exposed to good explanations of interfaces or when to use them. I am talking about interfaces in a context of interfaces vs. abstract classes. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Interfaces allow you to program against a "description" instead of a type, which allows you to more-loosely associate elements of your software. Think of it this way: You want to share data with someone in the cube next to you, so you pull out your flash stick and copy/paste. You walk next door and the guy says "is that USB?" and you say yes - all set. It doesn't matter the size of the flash stick, nor the maker - all that matters is that it's USB. In the same way, interfaces allow you to generisize your development. Using another analogy - imagine you wanted to create an application that virtually painted cars. You might have a signature like this: public void Paint(Car car, System.Drawing.Color color)... This would work until your client said "now I want to paint trucks" so you could do this: public void Paint (Vehicle vehicle, System.Drawing.Color color)... this would broaden your app... until your client said "now I want to paint houses!" What you could have done from the very beginning is created an interface: public interface IPaintable{ void Paint(System.Drawing.Color color); } ...and passed that to your routine: public void Paint(IPaintable item, System.Drawing.Color color){ item.Paint(color); } Hopefully this makes sense - it's a pretty simplistic explanation but hopefully gets to the heart of it.

Related questions

0 votes
    Could someone please demystify interfaces for me or point me to some good examples? I keep seeing interfaces ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    Could someone please demystify interfaces for me or point me to some good examples? I keep seeing interfaces ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 10, 2022 in Education by JackTerrance
0 votes
    Is there any reason for a class declaration to inherit from an object? I just found some code that does this ... class code follows... Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I'm learning the Python programming language and I've come across something I don't fully understand. In a method ... know very much. Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    I am a learner and just want to know the basic concept of super(). Here in the given code I want to know ... () ChildOne() ChildTwo() Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    There are two codes, what are the difference between them: Using type import types if type(q) is types. ... ): do_something_else() Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    Can someone please tell me the difference between a function decorated with @staticmethod and one with @classmethod? Select the correct answer from above options...
asked Jan 20, 2022 in Education by JackTerrance
0 votes
    I installed PEAR and when I try to run it, I receive this message: PHP_PEAR_PHP_BIN is not set correctly ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    Why does the AI seem so real and lifelike?...
asked Jan 30, 2023 in Technology by JackTerrance
0 votes
    I've following two path path1- test/hello/hello.php path2- test/hello1/hello1.php //notice the one ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    I've following two path path1- test/hello/hello.php path2- test/hello1/hello1.php //notice the one ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
...