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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:05:01+00:00 2026-05-31T03:05:01+00:00

I am working on an MVC framework in PHP but I work with java

  • 0

I am working on an MVC framework in PHP but I work with java primarily and I am looking for a solution to this problem which adheres to OOP principles and is transferable to other languages.

I have a model abstract class that interacts with some data (database, xml, whatever). Inheriting classes have to implement these methods:

abstract class Model {

abstract public function nextItem();

abstract public function insert(Map $item);

abstract public function update(Map $item);

abstract public function delete(Map $item);

abstract public function exists(Map $item);

abstract public function countItems();

abstract public function allItems();

The controller passes a Map object which holds information about an item that is to be inserted, updated, deleted etc. This means that the model and controller are decoupled and any Model can be injected into a controller provided there is an implementation of these methods.

When using this class in practice I have found that there have been instances where the operation needed by a controller is highly unique such as re-ordering data in a specific way. This is a BAD solution:

abstract public function reorder(Map $item);

This solution means that EVERY Model must implement this method which isn’t necessary. Also Imagine if I needed other methods, the amount of abstract methods would simply grow and grow, each needing an implementation.

Another solution would be this:

abstract public function action(Map $item, $action)

The $action variable would be a string that defines an action. So you could implement different methods but only call them with the polymorphic action() method:

if ($action === "reorder") { $this->reorder($item); }

The only problem with this solution is that the correct commands are not obvious from the method signature. For example the $action string could be anything and another developer would have to examine the method body (implementation) to find the admissible strings. Simply stating them in the documentation seems a flimsy solution. Also, what if a model is injected into a controller which doesn’t implement all the required actions? Throw an exception?

It seems like I must be missing some kind of really obvious solution and I don’t want to go ahead and implement the one above and then have to heavily refactor later when I find a better one. Any ideas?

Edit:
Using multiple interfaces seems to be the best solution so far. There is a type safety issue though. If I am to inject a Model which implements interface ReOrderable into my Controller class I want to be able to do __construct(Any Model that implements these interfaces $model). I could make more abstract classes such as ReOrderableModel and then do __construct(ReOrderableModel $model) but there could be any number of combinations of interfaces and I would have to define an additional abstract class for each one. I could also turn Model into an interface and use multiple interface inheritance but the same problem essentially arises. I must be missing something.

  • 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-31T03:05:03+00:00Added an answer on May 31, 2026 at 3:05 am

    I would define a, IReOrderable interface, and have your actual Model class implement this interface. It doesn’t need to be done at the abstract class level if it is not meant for all inheriting classes.

    I use one abstract Model class, and then a ton of Interfaces for the actual Model implementations.

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

Sidebar

Related Questions

I am currently working on a php framework, which is in some cases structured
I am building a custom MVC framework using PHP. My problem is when I
In the future I will be working with MVC with java/j2ee,hibernate,and more, but for
I am working with a custom MVC PHP framework and the index page (acting
I'm working with a PHP MVC Framework. Works really well. I like the separation
I am working on a small MVC framework, which will simply provide a more
I have my own hand-rolled PHP MVC framework for some projects that I'm working
I'm working on a small project, where I'm using the codeigniter php framework, but
I am working with an MVC framework with PHP and in my views I
I'm working on a small MVC framework (it's really very small) in Scala. I'd

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.