Too many methods

Have too many methods in a window. Is there a way to get them into groups?
If methods are independent of the window the use of modules is a solution, but when they have constant references to window’s objects or properties, etc. each reference must be preceded of “windowName.”
What is the best approach?, if there is one.

i think best grouping are classes / objects.
can you show a list of your methods?

Refactoring is your friend. Too many methods is a code-smell. Your window should talk to the model class which should talk to the functionality proper.

And your functionality absolutely should not refer to the window directly.

And modules for generic, often used methods. I keep several modules, each with methods of particular types. For example, I have a Module_Database for the various database methods, including database error handling; a Module_StringDate for (you guessed it) String and Date methods; etc. Putting them all in a Modules folder keeps things clean.

Already have all the in/out procedures in a separate modules (one for CSV reads, and another for SQL, and with classes for other purposes. I would investigate what’s Refactoring is, as Beatrix said.

[quote=466546:@Beatrix Willius]Refactoring is your friend. Too many methods is a code-smell. Your window should talk to the model class which should talk to the functionality proper.

And your functionality absolutely should not refer to the window directly.[/quote]
ummmm, Beatrix, when you refer to Refactoring do you mean creating a class that has a window in in? is it possible? where may I study about refactoring?.

Try “Clean Code” by Robert Martin. You should have smaller classes with a clearly defined job. The window and the functionality of your app should be decoupled.

One standard way is to have the MVC pattern - model view controller. I found the controller not to be of much use in Xojo. My main window delegates its calls back to the model, which calls the different classes. Then the model talks back to the window.

[quote=466557:@Beatrix Willius]Try “Clean Code” by Robert Martin. You should have smaller classes with a clearly defined job. The window and the functionality of your app should be decoupled.

One standard way is to have the MVC pattern - model view controller. I found the controller not to be of much use in Xojo. My main window delegates its calls back to the model, which calls the different classes. Then the model talks back to the window.[/quote]

The problem is I’m not skilled enough and I understand only partially you said. The approach I’m trying is to group in a class o module all procedures that share something, or deal with a part of the window’s task, that’s works, but, as I use large names for properties, methods, etc., to be as clear as possible for myself to understand the code, some calls o references are very long. Just the option to define folders inside the window/methods will help a lot.

I made a complete document based desktop application example. It’s free and open source on github. It is a great example of how to use the data and window separately. The data class reads and parses the JSON, the Window does window-ey things.

Check it out if you are interested GitHub - devtimi/Retinassets: Easily build CSS for HiDPI image assets

Thanks Tim I have dowloaded it and will study and try to understand.

You have to start somewhere to learn.

I forgot another book: Head First Design Patterns. The Xojo code is available at https://www.mothsoftware.com/content/xojo/xojo.php . The book is old but the principles don’t age.

Each piece of code needs to have one responsibility. Deciding what the responsibility is is a matter of preference. And you learn how to make the responsibility smaller and smaller.

What you feel as “too many methods” is a good point to start because you know you have a problem. Whenever you have a thorny piece of code then you have another indication that you have an organisation problem.

The Head First book teaches you the principles. The Clean Code book goes into more details.

[quote=466597:@Beatrix Willius]You have to start somewhere to learn.

I forgot another book: Head First Design Patterns. The Xojo code is available at https://www.mothsoftware.com/content/xojo/xojo.php . The book is old but the principles don’t age.

Each piece of code needs to have one responsibility. Deciding what the responsibility is is a matter of preference. And you learn how to make the responsibility smaller and smaller.

What you feel as “too many methods” is a good point to start because you know you have a problem. Whenever you have a thorny piece of code then you have another indication that you have an organisation problem.

The Head First book teaches you the principles. The Clean Code book goes into more details.[/quote]
Thanks a lot Beatrix, I’m getting down to study all this.

Christopher Okhravi made some videos referencing this book and goes through the design patterns.

Interesting, thanks.