-1

PROBLEM: In Javascript I use closures to encapsulated methods inside a class. It helps building hierarchy inside and minimize amount of methods at root, but they become lengthy.

RESEARCH: Applied to library classes or GUI frameworks classes (prototype-based inside).

QUESTION: Should I consider refactoring each root method into a separate class or keep them all thematically composed? Is the same applicable to other languages (Java)?

closed as unclear what you're asking by amon, Jörg W Mittag, Ixrec, user22815, Bart van Ingen Schenau Jan 22 '16 at 14:56

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

1

It sounds like you've discovered that you can use javascript closures to create classes. Doing this you can treat javascript as an object oriented language. But is this wise?

Look at java 8. Java is desperately trying to be more functional. It was originally intended to be an object oriented language.

Which you should lean towards, OO or functional, depends on how you expect your application to change. OO reacts well to the addition of new data types, that is new classes. It doesn't do so well when you wish to add new methods. Functional programming is the opposite. Adding new methods is easy, but adding new data types/structures can be very hard.

Javascript is powerful enough to let you develop either way. If you choose to go completely OO using closures you're predicting that most change will be about new data types.

  • OOP better fits my mind. Besides, there is a Visitor pattern that simplifies adding operations in OOP languages. – Zon Jan 20 '16 at 12:43
  • @zon Well I can understand wanting to stick with what you know. But bear in mind, many patterns from the gang of four have trivial implementations in functional languages. It might be worth learning them if you're going to work in a language that can do both. – candied_orange Jan 21 '16 at 6:14

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