This is a request for some 'best practices' comments from experienced OOP practitioners. I have been in IT from the days of punched cards and have had considerable experience with legacy languages like 370 ASM, SAS, and REXX. For fun, I've taken a college class in C++ and am now working on a program for my personal use.

I am building a program that will let me create, maintain, and search a database of articles from woodworking magazines and books I've gathered over the years. When I want to start a new project, I want to search this database for articles that I can use in my project. I'm doing the program in C++ with GTKMM and using a MYSQL database, all under Linux.

I've built tables in MYSQL for the source of the article (magazine name, book, etc.), type of source (magazine, book, clipping, etc.), the article category (indoor furniture, etc.), the date/vol/issue, and some info on the article (source, page, category, title, and short synopsis). Some of these tables are simply used for reference (ie, category, type of source) while others contain data (source, date/vol/issue, and article).

I have a working program to enter data and am now working on classes to let me search and view the records and let me edit them (to correct errors). In today's working program, I have a class for the database with methods to connect, write data, retrieve data, and will write a method to let me update data. I also have a class for the main window, to add new data to other tables (new source, new date/vol/issue of a source, new category), one to present a screen to let me select data to find, and I'm working on one that'll display the data.

My question is simple: Should I be designing this with classes that more-or-less corresponds to the tables (ie, a class for an 'article', one for a 'source', etc.) or as I'm doing it, a class for each process?

I'd appreciate any comments from those of you who have been doing this type of development for far longer than me.


Recommended Answers

All 2 Replies

I can't claim to be an OOP expert, I've only been studying it for a few months, but in my opinion, you're better off representing a physical object as a class.

Each class you define should corerespond to the construction of one of your tables. You would then use each record of a table as the description of an individual object. You should be able to produce a complete object from one query.

For example, you would have an "article" class that contains an instance of the "source" class and potentially other relative sub-objects within it.

Thanks, FBody! I'll rework my design to incorporate this and hope to make the code more elegant and tighter.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.