Notifications
Clear all

Object Oriented techniques - Example 2 - Display Manager

49 Posts
8 Users
83 Likes
4,461 Views
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2535
 
Posted by: @zander

I remember a similar example when I was first introduced to OOP. The question I had then was 'What has this to do with payroll, AR, AP, GL etc' Still a valid question, but of course programmers code much more interesting applications today and I do see some applicability but still question how much is gained in $ coding like this.

Consider the case where employee "tombstone" information like employee ID, names, address, hire date, title are stored in one table a corporate database. Other tables would contain data like employee number, vacation start and end date; employee number, salary, date salary started; employee number, source ID, date course taken; employee number, job title, date title assigned; and so on.

Now, imagine a well written (and tested) class that encapsulated all of this data. Remember that the class doesn't have to hold all of the details inside it, it just needs to be able to access it as needed. So it would provide (on demand) current job title, current salary as well as a list of job titles (promotion path) and list of salary levels and so on.

It should also be able to properly add a new salary and date to the appropriate database table, add a new holiday, change address and so on. Also, when management decides that they want to separate the employee's address into a new table (with address and date assigned), this is the ONLY place that major change has to be done, so it's easy to coordinate (overnight change the employee table, add the new table, change the class source in the corporate source library and then recompile everything before tomorrow).

So, only one class needs to change. A beneficial side-effect of this is that most of the corporate IT section does not have to know the database design, they access it only via the classes, so details of the storage location and methodology are of no importance to them.

There will be a subset who are responsible for writing the classes and maintaining them and the database. They will require more detailed information and probably more money.

But you can see how much easier it will be for the main body of programmers who only need to be familiar with the class methods.

Anything seems possible when you don't know what you're talking about.


   
Biny reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7012
 

@will I properly designed 3rd normal form DB would probably solve that in that era, today, SQL would do it but maybe SQL is the real world realization of OO data.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
Biny reacted
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1122
 

@binaryrhyme

Thanks for you good examples of user programmed OOP classes, but the fact that some had difficulty in finding your various tutorial posts do illustrate that providing tutorials in a forum such as this is probably not the best format and your thoughts (or someones thoughts) on providing example code on github may be a much better medium.

A lot of talk about newbies being confused is I think rather off the mark as newbies have more fundamental learning to achieve.  I'm thinking you aimed this at those who have grasped coding in Arduino C and can use and understand the code snippets as shown in the likes of Dronebots Workshop but are wondering if delving into other aspects of C++ is where they wish to go.  

For most of the coding I have done with Arduino's or other microcontroller boards I may not find much advantage of OOP classes that I construct myself, the programs are just not that big and where I need to reuse code cut and past is remarkably efficient. 😀   

However I can see the use as per the example video I linked to on your first post - the use of comprehension over inheritance to swap out classes for various sensors that may be attached to the microcontroller and to construct some reusable classes.  But would it be worth it?  Of course I'm just twiddling with Arduino sketches maybe a couple of dozen times a year and I have not felt the need to use classes for those type of sketches.  

Therefore, should you be considering providing more examples, I think actual examples of microcontoller programs that you actually use that illustrate the benefits of the use of classes in microcontoller environments would illustrate the 'why be bothered'.

Now this does not apply to programming database or GUI programs running on the likes of a rpi where constructing classes is advantageous and indeed often necessary (as in constructing a GUI in pyqt5) though my programming on the rpi is all done in python.  Your examples of user programmed classes in this respect would be very applicable should one wish to program in C++

Indeed now that microcontrollers also come with larger memory and probably will have larger programs constructed to run on it, one would find the use of user programmed classes to be of benefit.  I've just got a TinyPico ESP32S3 with a whopping 16mb flash plus 8mb PSRAM so plenty of scope to consider some rather large programs, though for what I do not yet know 😎.  (for me, for the ESP boards,  I preferentially use micropython for the better prototyping abilities and would only go to C++ where the need for greater speed is warranted.

Anyway just some observations to take or leave, and again, thanks for your efforts with your tutorials.


   
Biny and Ron reacted
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2535
 

@byron 

Python is considered to be an OOP language 🙂

Anything seems possible when you don't know what you're talking about.


   
Biny reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7012
 

@byron I agree, the forum needs a file section that I see in other forums. It could even include 'stock answers (just the forum link?) for common questions like the recent ESP 5V/3.3V discussion that @davee provided in Dave E's ESP power response This would be a place to store any kind of coding examples that the general community might learn from.

I agree with you entirely re newbies and fundamentals. If a person is so new they have not yet mastered syntax, OOP concepts are waaaaaaay over their head. BTW, git may also be too advance, that's why I think a simple files section is better.

It would be helpful to use examples that are micro computer/controller specific, a draw class or shape class is not anything I can relate to, but the LED class is although I consider that too simplistic but I have over 50 years experience so I am not a good newbie judge.

I now have a folder on my desktop with forum links to 'stock replies' started.

Is it not a good idea to be able to point a newbie to such a section of the forum and simply say read file xyz then come back if you have further questions?

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
Biny and byron reacted
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1122
 
Posted by: @zander

Is it not a good idea to be able to point a newbie to such a section of the forum and simply say read file xyz then come back if you have further questions?

I do agree with that suggestion, but I do think that tutorial examples are best left without without an abundance of observation postings in the same post not to confuse the original posters intention.  

So in that respect I'm thinking along the lines of github were there is a code section and an issues section where observations , questions and comments can be put, and the original poster can choose to answer, amend the code, or ignore as is seen fit.


   
Biny reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7012
 

@byron That sounds reasonable, but I like many do not know git. I know it enough to download a library zip and install it, but the rest of the screen is mostly greek (FYI I don't understand greek). Same for discord. I have heard of git of course before, but thought of it as a pro tool not something for casual users.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
Biny reacted
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1122
 
Posted by: @will

Python is considered to be an OOP language 🙂

Oh yes its very OOP 😀.  However often the use of plain old functions can sometimes trump the use of classes as function are first class objects that can be passed as object and means there are other possibilities from the traditional OOP approach.  I do like python 😎 


   
Biny reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7012
 

@byron I see there is Python, MicroPython and even CircuitPython. Care to comment on each?

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
Biny reacted
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1122
 
Posted by: @zander

I see there is Python, MicroPython and even CircuitPython. Care to comment on each?

Python is one of top languages, along with C++ or C# and Java that are used the development of large projects in the wide world.  

Micropython was a project developed a few years back, 2014 I think, where the python language was programmed in C for use on microprocessors. Originally this was just the pyboard, but ports are available for a whole range of boards including the ESP8266, ESP32's rpi pico, Teensy 4, Arduino RP2040 connect, etc.  Its not available on the older Arduino uno boards.   The rational was that its easier to use and faster to prototype (one can type statements into a Read Evaluate Print Loop for an instant response without needing to compile).  Some python libraries and modules are not present or for some modules only a subset of the functionality is provided.  Its based on python v3.4 whereas python is now at v3.10.  However micropython is a very complete version of python, and not much is lacking.  Its now being used in commercial environment for embedded programming, though in this respect C implementations are by far the most common.

Adafruit, who sells a lot of sensors and microcontoller boards ported micropython to be used on several of their boards, but subsequently developed CircuitPython which is based on micropython.  The idea of CircuitPython was to provide a lot of libraries to make use of the components and boards they sell and for new users to easily get to grips with programming.   CircuitPython lags behind micropython releases, for example it did not have interrupts or asyncio (asynchronous programming) implemented. (they just released a version of asyncio).  However Circuit python provides a large number of circuit python libraries to make use of a large number of peripherals along with example code.


   
Biny and Ron reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7012
 

@byron Of course COBOL is still dominant in many business environments, almost all ATM transactions, about 45% of other banking. Although I debugged other peoples COBOL, I never learned it and never wrote a complete program. I did add/modify a few lines at 3AM when troubleshooting a major financial system and the regular programmer was away but that probably only happened 2 or 3 times in my entire life. Once with the president looking over my shoulder because the next day was profit day.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1122
 
Posted by: @zander

Of course COBOL is still dominant in many business environments,

There must be a lot of legacy code still around, as for amusement I google the top 10 programming languages, and whilst I was at it I google COBOL.  It seems all the old COBOL'ers are fading away and there is now a shortage of COBOL skills and its back in demand!

For anyone interested the top 10 programming languages are reportedly 

  1. Python
  2. Java
  3. JavaScript
  4. C#
  5. PHP
  6. C/C++
  7. R
  8. TypeScript
  9. Swift
  10. Objective-C

What the heck is R 🤔.  No, I don't really want to know, I'm sticking with what I know works for me. 😎 


   
Biny reacted
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2043
 
Posted by: @byron
Posted by: @zander

Is it not a good idea to be able to point a newbie to such a section of the forum and simply say read file xyz then come back if you have further questions?

I do agree with that suggestion, but I do think that tutorial examples are best left without without an abundance of observation postings in the same post not to confuse the original posters intention.  

So in that respect I'm thinking along the lines of github were there is a code section and an issues section where observations , questions and comments can be put, and the original poster can choose to answer, amend the code, or ignore as is seen fit.

Stand alone tutorials are not suitable to a forum of this kind IMHO. You cannot even edit the first post, as is possible in some other forums, as a single source of information as a project is updated.

 


   
Biny reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7012
 

@byron My background is corporate so none of those languages were used, then securities, and we started out with PL1 but then switched to C since PL1 programmers were hard to find. The special computers that ran the securities applications had a 3 stage compiler. The same code got generated regardless of language (stage 1) and ran on several platforms (stage 3) including MC68000, HP, PowerPC, Intel. RISC and CISC. We could change platforms overnight without the customers knowing or being adversely affected. Very cool software. FreeRTOS bears a similarity to VOS (Virtual Operating System), VOS was created by Multicians.

Measuring by lines of code installed there is no doubt Cobol would be #1, C probably #2

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
Biny reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7012
 

@robotbuilder That is one reason why I suggested the addition of a Files section like other forums I am on. On those we regularly refer newbies to read a certain doc in the files section.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
Biny reacted
ReplyQuote
Page 2 / 4