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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T09:36:43+00:00 2026-05-14T09:36:43+00:00

from what i’ve read it seems that one can interact with an interface? eg.

  • 0

from what i’ve read it seems that one can interact with an interface?

eg. lets say that i’ve got an interface with an empty method “eat()”

then 2 subclasses are implementing this interface.

can my controller interact with only the interface and use it’s eat() method?

have a look at the picture in this link strategy

  • 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-14T09:36:43+00:00Added an answer on May 14, 2026 at 9:36 am

    You cannot interact with an interface except for accessing any defined constants in it or using it for TypeHints. Interfaces do not have method bodys. They are solely meant to define a contract implementing classes must obey.

    interface Logger
    {
        const FOO = 1;
        public function log($msg);
    }
    
    echo Logger::FOO;  // 1
    Logger::log($msg); // Fatal error: Cannot call abstract method Logger::log()
    new Logger;        // Fatal error: Cannot instantiate interface Logger
    

    See http://php.net/manual/en/language.oop5.interfaces.php


    What is generally meant when coding against an interface or interacting with an interface is basically nothing more than calling methods defined in an interface in the classes implementing them. You call the implementation, not the definition. The definition just specifies that for every Class implementing the interface, there has to be a specific method with the specified arguments.

    Consider these classes:

    Class DbLog implements Logger 
    {
        public function log($msg) { /* log $msg to database */ }
    }
    
    Class FileLog implements Logger
    {
        public function log($msg) { /* log $msg to file */ }
    }
    

    Both classes implement Logger and therefor have to have a method log($msg). You’re basically saying: “hey class, if you want be a Logger, make sure I can call log() on you.”. Now somewhere in your code you might have a class that needs a logger, like

    class Foo
    {
        protected $logger;
        public function __construct(Logger $logger)
        {
            $this->logger = $logger;
            $this->logger->log('I can haz logger! Yay!');
        }
    }
    

    Foo doesn’t care if it gets FileLog, DbLog or any other concrete Logger. It just cares that it gets any Logger it can call log() on. Foo isn’t even interested in what log() does. All Foo cares about is being able to call log(). You’re not calling log() in the interface though. You are calling it in the conrete class that was passed to Foo, but in an UML diagram you’d represent this like it’s shown in the page you linked, because you just coded against an interface.

    The main advantage of this is that your classes are much less coupled. You can more easily swap out dependencies, for instance when using Mocks in unit-testing, and your code will be more maintainable.

    Basically, think of an interface as a conceptual standardization. For instance, when you buy a new DVD Player, you expect it to have a ► button that somehow (you don’t care how, just that) makes the player play the DVD. When you press that button, you’re not pressing the general abstract DVD interface specification that says a DVD player must have a play button, but you clicked the concrete implementation of a play button on this brand of player.

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

Sidebar

Ask A Question

Stats

  • Questions 367k
  • Answers 367k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer UPDATED: DEMO http://jsbin.com/itivu3 SOURCE http://jsbin.com/itivu3/edit NOTE: taking in mind what… May 14, 2026 at 5:02 pm
  • Editorial Team
    Editorial Team added an answer Nope, you can only submit one form at a time.… May 14, 2026 at 5:02 pm
  • Editorial Team
    Editorial Team added an answer use yourNumericUpDown.Select(desiredPosition,0) May 14, 2026 at 5:02 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.