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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:29:55+00:00 2026-06-12T21:29:55+00:00

There are a few places where I’ve executed logic based on what interfaces a

  • 0

There are a few places where I’ve executed logic based on what interfaces a class implements – is there any reason that this may or may not be wrong? (It feels dirty)

The reasoning behind doing this was so you don’t have to add any class properties or methods to determine these things, basically in the class definition you can spell out explicitly what it could / could not do.

One use case is ajax calls, some require you to be logged in and some don’t:

class ajax_ads extends ajax_controller implements no_login {

}

Also, there are no methods in the interface, it is used soley for this purpose.

interface no_login {}

Then in the base controller:

$controller = controller::factory()
if( !($controller instanceof no_login) && !$controller->LoggedIn()){
    return $controller->redirect(/*login page*/); 
}

It seems lightweight and simple to use instance_of and it works fine, but again it feels like I’m totally abusing the purpose of the interface.

So I ask, is using an interface to determine logic a bad idea, bad oop, or ‘okay’?

  • 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-12T21:29:56+00:00Added an answer on June 12, 2026 at 9:29 pm

    When you need an if or a switch to determine the state an object should be, it’s usually a good sign you are in need of polymorphism.

    In your case, there should be one abstract class: Ajax_Ads, and two extending classes: No_Login_Ajax_Ads extends Ajax_Ads, and Login_Ajax_Ads extends Ajax_Ads. And you instantiate the one you require based on the state of the program, this could be done with a factory.

    For more information, watch the following lecture: The Clean Code Talks — Inheritance, Polymorphism, & Testing

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

Sidebar

Related Questions

There are a few windows service projects in our codebase that follow this model,
There are a few minor places where code for my project may be able
I know that there are a few Questions here on SO relating to this,
Is there any slide bar widget to which i will place few icons and
I have an application that's locked down using forms authentication. There are few nightly
This has come up in a few places, but I'll use footnotes as an
I have a few places where I have a generic type parameter that is
I'm refactoring some code. Right now there are quite a few places with functions
I have a few places in a model that does stuff like def ServerInfo.starttime(param)
I have a few places where I use a class via jquery - for

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.