1

I'm building an app with the usual layers like presentation, application, infrastructure. Right now, I have been using WordPress functions in both my controllers and repositories. I figured that controllers need to be re-written anyways should the framework change, and repositories are part of an implementation (like WordPressUserRepository), so it figured this would be okay as well.

Is there a general consensus about framework functions in layers? I feel more and more that my code gets too coupled to the framework...

1 Answer 1

1

The definition of a framework is pretty much that you are locked in to using it. The framework dictates your architecture. Your code is interwoven with the framework. It's like choosing the programming language. You cannot change the framework without a near-complete rewrite.

If you try to isolate your code from the framework you are fighting the framework at every step instead of letting it help you. Things become twice as difficult, because in addition to writing your actual code you will often have to write the necessary wrappers. These wrappers end up being their own in-house framework that no one else knows.

There are ways to limit the impact of a framework choice. E.g. your business logic (if there is any) will likely be completely independent of the framework. Instead of a layered architecture Views -> Model -> Data it is possible to choose something like the Onion Architecture where the dependencies are Views -> Model <- Data. I.e. the Model doesn't depend on the other parts. If the views and data interfaces make use of a framework, that will not affect your model, i.e. your business logic. But this can also mean that you cannot benefit from patterns like ORMs that are embedded into your model.

In many cases, speed of development is more important than strategic flexibility regarding future framework changes. This flexibility would just lead to over-engineered solutions. A comprehensive framework that assists in all parts of the application is then welcome, even if your code becomes inseparable from that framework. This is your choice.

2
  • I was thinking about the DDD mantra that frameworks are "just an implementation detail". But looking at it from a practical point of view, changing the framework seems rather unrealistic - like buying a Ferrari and then deciding that you want a Lamborghini engine for it, this usually doesn't happen in real life. I do agree about the business logic part - I don't use any framework functions in that layer. And the speed of development is another good argument. Thanks.
    – Hans
    Aug 17, 2018 at 17:26
  • There is a use case where I need to check whether the client that is requesting a project view is the one that is associated with this project. I wanted to do this check in the controller, because it's fairy simple. So my initial approach was to write a AssociatedClientQuery interface and then a WordPress implementation for that interface. The implementation would simply call a get_post_meta( $projectId, 'client_id' ) and return the string. But reading your answer, I might aswell call that function directly in the controller. Should I simply stop writing interfaces for my framework?
    – Hans
    Sep 1, 2018 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.