|
My take:
A class should group related data and actions that center around a single concept. A car class might contain 4 Tire class instances as data members, an Engine instance, and a Gearbox instance. Each one has actions relevant to its operation like Engine.Start(), and Wheel.Rotate()
But I'm hearing that professors are teaching that classes are effectively a single action like ReadTextFile and it makes me a lot more irritated than I probably should be.
Am I wrong here?
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
I'm not a OO person but it seams like TextFile.read() encapsulates much better what action is being performed on an instance of TextFile than TextFileRead which might be applied to some unknown object that may or may not support "read". Or worse, has subverted TextFileRead to do something totally unrelated, like open a can of beer. Maybe the Profs in question are confusing an interface with a class? Dunno. Seems wrong to me.
Keep Calm and Carry On
|
|
|
|
|
Your take is the way I learned it.
I thought it was the way Bjarne Stroustrup intended it.
I’ve given up trying to be calm. However, I am open to feeling slightly less agitated.
I’m begging you for the benefit of everyone, don’t be STUPID.
|
|
|
|
|
He designed C++ not OOP
In a closed society where everybody's guilty, the only crime is getting caught. In a world of thieves, the only final sin is stupidity. - Hunter S Thompson - RIP
|
|
|
|
|
pkfox wrote: He designed C++ not OOP
No one person "designed" OOP.
Like many concepts it evolved over quite a long time with different people working on the concept.
And at least when the "C++ Programming Language" was published for available books there were perhaps only four (or three) of them. And two were on C++. The concepts in all were basically the same.
|
|
|
|
|
But he explained OOP that way and the implmentation in C++ was that way as well.
I’ve given up trying to be calm. However, I am open to feeling slightly less agitated.
I’m begging you for the benefit of everyone, don’t be STUPID.
|
|
|
|
|
Mixing (up) function(s) and actions.
ReadTextFile is some clumsy rewording of a "TextReader" class.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
In this case it was part of an assignment to read phony medical records from a CSV.
A more horrible name I could scarcely fathom. I was helping with their homework, and trying to teach them what their prof wasn't.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
I would say TextReader is the superclass of ReadTextFile. Text doesn't always come in files.
|
|
|
|
|
Personally I can't make a bridge between ReadTextFile and the car...
Anyway you example shows a classic thing, that classes are usually not 'stand alone' and in a certain way 'connected'/'depended'
Your examlpe:
Engine.Start() does depend on the state of the Gear. Either Engine asks the gear for 'I'm ready to start' or the gear sends a message to the engine 'hey, I'm at gear 1 (without pressed clutch), not really good to start at the moment' and so on and on and on...
Abstracting the reality is usually very hard.
Only my two cents.
|
|
|
|
|
Of course, but I was simplifying and glossing over details to simply get to the larger point, to wit: In my mind, a class is a noun, not a verb, essentially.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
honey the codewitch wrote: a class is a noun Not really, since a class encapsulates properties (nouns), and actions (verbs); so it could be an ablative gerund.
|
|
|
|
|
Holy ...
Dear Richard, you know me now for a longer time as an English non native. Can you please describe 'ablative gerund' in _very simple words_ for me?
Thank you very much in advance
|
|
|
|
|
lol
Apparently it does mean something. I googled it just to be sure. But I still didn't understand what it means.
|
|
|
|
|
=> Conclusion: You are not native English, at least not british native
modified 6-Nov-23 18:35pm.
|
|
|
|
|
English has gerunds (a verb ending in -ing that also functions as a noun) but no ablative case[^].
|
|
|
|
|
Thank you Sir. But is this also available in easy words
|
|
|
|
|
I believe ablative gerund belongs to latin grammar, and there is no such thing as easy latin.
But I'm probably wrong though, as I never learned latin.
|
|
|
|
|
Awesome rabbit-hole
|
|
|
|
|
Ha ha! I remember "ablative" and "gerund" from my Latin classes back in the 1950s. So I just put the two words together as a joke. But the joke, it appears, is on me, as there realy is such a thing. But I am not sure exactly what that thing is.
|
|
|
|
|
|
I think I would rather read a PHD research article on string theory.
|
|
|
|
|
LOL.
So I am not the only one.
|
|
|
|
|
honey the codewitch wrote: In my mind, a class is a noun, not a verb, essentially For me, a class may be either a noun or a verb.
As a noun, the concept represented by the class is a thing, and the class provides information and operations for that thing.
For a verb the concept is a process, and the class supports that process. I guess 'process' can be thought of as a noun, but thinking of it that way adds indirection to my thinking.
Software Zen: delete this;
|
|
|
|
|
That's a good point. I was trying to get to the essence of it and simplify, but obviously I missed the mark in terms of covering every eventuality.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|