Software Architecture for Reusable Code

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
User avatar
ColleenKobe
Earned some good credits
Earned some good credits
Posts: 109
Joined: Mon Aug 31, 2015 3:47 pm

Software Architecture for Reusable Code

Post by ColleenKobe »

I am writing a class in C++ using wxWidgets and wxCrafter, minGW and CodeLite (see versions below). The class will contain procedures to build wxDialogs with controls to call procedures and functions to process data. Ordinary tasks.

My project engineer wants me to write the class so that I can "just drop it into" future work projects.

I am still new to OOP and coding in CodeLite and wxWidgets in general.

So, my question is, what's the best way to go about writing the class so that it can be "dropped into" a future CodeLite workspace? Would it be to make the class its own CodeLite project, and then in a future CodeLite workspaces, "Add an Existing Project"? That's the only solution that I can come up with now, but I thought there might be a better idea out there.

Thanks!

Software Versions

Code: Select all

CodeLite    10.0.4
gcc          4.9.3
tdm-gcc      5.1.0.2
Windows 10  Pro, 64-bit
wxWidgets    3.1.0
wxCrafter    2.6

Target platform   32-bit
Target build   debug
coderrc
Earned some good credits
Earned some good credits
Posts: 141
Joined: Tue Nov 01, 2016 2:46 pm

Re: Software Architecture for Reusable Code

Post by coderrc »

no_cat.meme
Forget about codelite. tomorrow you might be using anything else and on the third day you may find yourself using vim.

Just write your class like you would any other class. You drop it into a project by "add existing item" or the equivalent in your IDE, or even just compiling it as a library then #including the relevent headers and linking against it when you need it.

but the point here I suppose is to be generic. That way it can be used in this project, and in your future stock ticker project and in your fighter jet HUD project, and in your pet feeder project and in ...

So without cramming a bunch of terminology down your throat, let me give you an analogy.
Right now you need a screwdriver with a pointy end. Tomorrow you might need a screwdriver with a flat end.
So you have two options.
1)You can either make two different screwdrivers that are essentially the same except for the ends.
OR
2)You can make a single screwdriver with interchangeable ends, so if at some point you need a screwdriver with a different end than what you have, all you have to do is make the end bit.

The option you need to pick is 2.

in C++ this can be done with "virtual" functions.
As an additional tip, try not to #include anything that isn't absolutely necessary. like if you #include <boost>, then you will have to use boost in any project that uses your class.

here are some links to give you some idea
https://en.wikipedia.org/wiki/Virtual_inheritance

and on this page look at the graph, and then the function list below it. then see how it relates to the wxwidgets source code and how the source directories are laid out.
http://docs.wxwidgets.org/trunk/classwx_frame.html
DavidHart
Site Admin
Site Admin
Posts: 4254
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: Software Architecture for Reusable Code

Post by DavidHart »

Hi,

It depends on what is meant by "just drop it into future work projects".

One generic answer would be to put the class into a library. That way future projects can access the calls easily, by linking to that library.

Regards,

David
User avatar
ColleenKobe
Earned some good credits
Earned some good credits
Posts: 109
Joined: Mon Aug 31, 2015 3:47 pm

Re: Software Architecture for Reusable Code

Post by ColleenKobe »

coderrc wrote: [snip]Just write your class like you would any other class. You drop it into a project by "add existing item" or the equivalent in your IDE, or even just compiling it as a library then #including the relevent headers and linking against it when you need it.

but the point here I suppose is to be generic. [snip]
2)You can make a single screwdriver with interchangeable ends [snip]
The option you need to pick is 2.

in C++ this can be done with "virtual" functions.
As an additional tip, try not to #include anything that isn't absolutely necessary. like if you #include <boost>, then you will have to use boost in any project that uses your class.

here are some links to give you some idea
https://en.wikipedia.org/wiki/Virtual_inheritance

and on this page look at the graph, and then the function list below it. then see how it relates to the wxwidgets source code and how the source directories are laid out.
http://docs.wxwidgets.org/trunk/classwx_frame.html
You've stated my problem very well, coderrc. Thank you for the suggestions and the links! I'll investigate them today. :-D
User avatar
ColleenKobe
Earned some good credits
Earned some good credits
Posts: 109
Joined: Mon Aug 31, 2015 3:47 pm

Re: Software Architecture for Reusable Code

Post by ColleenKobe »

DavidHart wrote:[snip]One generic answer would be to put the class into a library. That way future projects can access the calls easily, by linking to that library.
[snip]
Thank you for your suggestion, David! So I would need to compile and link to get a *.dll, correct? Then when that code is needed for another project, I'd need to get the *.dll and *.h file, and that's it, right? The "calling code" would #include the *.h file, and I'd set up the linker to look for code in the dll. That should certainly work.

Thanks again!

Colleen
Post Reply