How to structure your FLTK C++ Application Project

134 views
Skip to first unread message

hans.t...@googlemail.com

unread,
Aug 16, 2018, 12:23:23 PM8/16/18
to fltk.general
I just have found that the classes in my application have a lot of dependencies, Spaghetti code is the only way to describe what I ended with. So I started a complete refactoring, creating modules that can compile and even run independently from the other modules. The non GUI part of the application is already separated in such independent modules. Now I'm having to find a structure for my main application and the part handling the GUI. My application uses a multi window approach, it has to handle an arbitrary number of document windows and runs on macOS.

I've been searching on the web and even thumbed through some of my C++ books, but I could not find anything useful. In this group I came across this message, that addresses my questions a little bit:
https://groups.google.com/d/msg/fltkgeneral/aM_uAEUSx_8/u1HSdMVq12gJ

Are there any good tutorials (not necessarily specific to FLTK) on structuring your code into modules and classes? Is there a (not too complicated) open source example project using FLTK?
Something link that would be great, but with a document based approach:


David Topham

unread,
Aug 19, 2018, 9:51:49 AM8/19/18
to fltk.general
Here are some good ideas on organizing GUI projects from Martin Fowler...
https://www.martinfowler.com/eaaDev/uiArchs.html

hans.t...@googlemail.com

unread,
Aug 20, 2018, 4:03:53 AM8/20/18
to fltk.general
Thank you, that's an interesting article. But I'm actually looking for something more practical instead.
I now have an approach that separates a lot of logic in its own classes, I hope my new code is easier to read and to maintain now.

duncan

unread,
Aug 20, 2018, 7:48:42 AM8/20/18
to fltk.general

Are there any good tutorials (not necessarily specific to FLTK) on structuring your code into modules and classes? Is there a (not too complicated) open source example project using FLTK?

There was a whole series of articles by Robert C. Martin (an editor of the now defunct C++ Report) and his colleagues at Object Mentor on how to structure code so that it is easy to extend, reuse and maintain, but the articles don't seem to be available on "public" sites anymore. You can explore some of them in a slightly more abstract form via https://en.wikipedia.org/wiki/SOLID 

He also put these together in a book "Agile Software Development: Principles, Patterns and Practices" but switching to Java for the example code. The whole point of these articles is that effort is required at the Design stage, with emphasis on Test Driven Development supported by UML diagrams.

You might also be interested in "Working Effectively with Legacy Code" by Michael C. Feathers (also of Object Mentor) in how to refactor existing code to make it more easily testable. You will need to be fluent in "Design Patterns" by Gamma, Helm, Johnson and Vlissides.

You might be able to find "The Humble Dialog Box" paper by Michael C. Feathers as a way of designing abstract interfaces for user interfaces.


duncan

unread,
Aug 21, 2018, 3:08:21 AM8/21/18
to fltk.general

Are there any good tutorials (not necessarily specific to FLTK) on structuring your code into modules and classes? Is there a (not too complicated) open source example project using FLTK?

There was a whole series of articles by Robert C. Martin (an editor of the now defunct C++ Report) and his colleagues at Object Mentor on how to structure code so that it is easy to extend, reuse and maintain, but the articles don't seem to be available on "public" sites anymore. You can explore some of them in a slightly more abstract form via https://en.wikipedia.org/wiki/SOLID 

He also put these together in a book "Agile Software Development: Principles, Patterns and Practices" but switching to Java for the example code. The whole point of these articles is that effort is required at the Design stage, with emphasis on Test Driven Development supported by UML diagrams.

and scroll to the bottom for access to the articles and/or book extracts.
All of these were heavily influenced by XP and Test Driven Programming
so are ideas for the design phase, rather than for refactoring existing code

Lots of really interesting stuff, but you have to be disciplined to apply it.

D.

Daniel G.

unread,
Jan 23, 2019, 11:08:43 AM1/23/19
to fltk.general
For normal GUI applications the MVC concept using the Observer Pattern is definitely a neat way to seperate the presentation from the business logic. In most cases, there is no need for a controller, but its always nice to implement one, just in case of drastic interface changes in the Model (Adapter Pattern, Controller = "just in case adapter" for Model).

For an example here is a template I created for my projects: https://projects.nwrk.biz/projects/fltk-mvc-templ

Fabien Costantini

unread,
Jan 24, 2019, 3:19:46 PM1/24/19
to fltkg...@googlegroups.com
A long time ago, I developed a fairly large fltk based VR prototyping application for the plane industryy and published a paper about the extended design patterns I used, one of them the categorized observer pattern you may find interesting to read:


 
-Fab



From: 'Daniel G.' via fltk.general <fltkg...@googlegroups.com>
To: fltk.general <fltkg...@googlegroups.com>
Sent: Wednesday, January 23, 2019 10:08 AM
Subject: [fltk.general] Re: How to structure your FLTK C++ Application Project

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Daniel G.

unread,
Jan 25, 2019, 11:36:25 AM1/25/19
to fltk.general
Interesting paper, thanks for sharing :)
Reply all
Reply to author
Forward
0 new messages