Can Controller have private methods?

Asked

Viewed 71 times

2

I have a question and wanted to hear more people’s opinion. Following the MVC, one Controller can have private methods? This doubt came to me because in my context, I have a Controller JS, and my View is a page HTML. Well, if the Controller exists to control the View, it doesn’t make much sense to have private methods, since the View I couldn’t use it, or it makes sense! Maybe I’m getting a little confused.

  • 1

    Which MVC technology?

  • 1

    private methods can (and should) exist, even because they support/assist public methods, even facilitating the reading of your code.

  • @gypsy-Morrison-Mendez, did not understand your question, sorry!

  • @andrepaulo, but these private methods should be more generic, right?! If so, would it not be more appropriate to create a Utility and place these methods?! This would take private functions out of the controller.

  • Then you will have a "sausage" in Utilities ...

  • @Danielsilveira I asked why, depending on the MVC technology (the language, the framework, the convention, etc.), the implementation and the approach are completely different. Answer this by detailing the various implementations would be gigantic.

Show 1 more comment

1 answer

2

Sometimes we want methods that can only be accessed by the controller itself, such as calculations, state changes, among others. This way, the view will not have direct access to these methods, only from other methods.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.