|
I mostly do C# these days. But I find that when I am designing a dialog box for a program, I usually need more than a single primitive value returned. What I seem to end up doing is writing an embedded class to handle all the returning data. I make it an embedded class because I can keep it associated with that dialog box. Using a class gives it an instance that doesn't vanish the moment the dialog closes. There have been a few occasions when I've decided that an embedded class was a good solution as a class to handle multiple issues in a project. When I get to that point, I usually elect to change the class from embedded to a separate file.
|
|
|
|
|
Question: explain to me how putting data in an embedded class solves any problem? If the instance of the dialog (which is an object) sticks around, then the public data is still available. Embedding an object within an object seems over complicated to me. Double encapsulation?
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
I'll have to look at some of my project code and get back with you, as it half past midnight here, and I am a bit fuzzy on why. I know that the way I write my dialogs aren't quite as trivial as textbook examples, and I have to look and see why. But what I think I was doing was not so much as embedded a class within a class, but simply putting my data class on the end of the dialogbox class, initially, rather than having a separate file for the data class. It may relate to my wanting a dialog box that had an Apply button implemented in addition to the usual OK and Cancel buttons. It may be that my dialog box does something complicated and has to stay open and effect the target form with changes as I make them on the dialog without closing and reopening the dialog repeatedly until I get the combination I want.
|
|
|
|
|
Okay, I'm feeling your direction. It seems like you separate all of your dialog processing from any data processing. MVC light? Anyway, my dialogs tend to just do things. The times I need to obtain data from a dialog, I'll either make it publicly available or add a wrapper method to the dialog class.
Interested in your follow up comments.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
Perhaps a dialog's returning a custom data class wasn't the best argument. I think I have a better argument for an embedded class, anyway. I'm working on a class that programmatically displays rectangles of specific color samples, and the user is expected to click on the particular rectangle to select a color. OK, nothing special about that. I am displaying the colors in a matrix of rectangles that are programmatically generated panels, given a generic List of colors that I want to present. After I got deep into the coding, I decided I wanted to have a border around every rectangle, where the color of the border signified which palette the color was in. Not that there are expected to be a lot of palettes, maybe 1, 2 or 3. But I ran into a problem: the panel control doesn't have a means to define the color of it's border. I posed that problem to ChatGPT, and it suggested I write a custom Panel class that extends the standard panel class and showed me how I could override paint to put a border of any specified color around the Panels I am creating. I don't plan to use this custom panel class anywhere else, it is short and to the point, and there seems no reason yet for having it in a stand-alone file.
Steve
|
|
|
|
|
okay, I can see that a private class that is used in that one location. what I'm fighting with is that everything is public.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
I always try to use the right tool for the right job.
|
|
|
|
|
I agree, but what I am seeing is a coding style vs a design approach.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
Actually, I often do. A classic example is defining an Iterator class for a container type. It makes more sense to have the Iterator class definition be part of the container class definition (and hence called MyVector::Iterator, for example, than to create a separate MyVectorIterator, and typedef the Iterator type in MyVector.
Another example is a Pimpl pattern, although in this case the embedded class is just a declaration on the public interface, and the actual definition is in the implementation file.
|
|
|
|
|
Only if there is a specific reason to do so.
One use case is that there are a lot of friends of the main class but I want tighter control over users of the embedded class.
|
|
|
|
|
Statement 1: Every rule has an exception.
Statement 2: Statement 1 is a rule. Therefore Statement 1 has an exception.
Conclusion: There is at least one rule which has no exception.
Would you agree with this conclusion? If so, is there any example of a rule having no exception?
|
|
|
|
|
Friends don't let friends program in Basic.
If you can't find time to do it right the first time, how are you going to find time to do it again?
PartsBin an Electronics Part Organizer - Release Version 1.4.0 (Many new features) JaxCoder.com
Latest Article: EventAggregator
|
|
|
|
|
Kurt Gödel proved a version of Statement 1:
In any formal language, there are questions that can be asked but not answered.
A perfect example of Gödel's incompleteness law can be found in math:
- Positive Integers (lengths) can subtract a larger number from a smaller number. The answer is a negative integer, leading to:
- All integers can divide and result in a fraction, leading to:
- Fractions can be used in geometry to result in real numbers, leading to:
- Real Numbers can have square roots that are imaginary, leading to:
- Complex numbers, etc...
|
|
|
|
|
I always think of Godel’s Completeness/Incompleteness theorems when people invent new encoding systems, etc.
XML : How do I encode “<“?
<
Well how do I encode ampersand?
&
etc.
CSV How do you encode a comma?
Enclose it in quotes.
How do you encode a quote?
Double it!
My practical interpretation:
Define a system: There will always be something outside of its boundaries!
My favorite example is good old
int getc();
It returns a char or -1 for EOF/End of File. EOF is outside of the char system.
|
|
|
|
|
|
In a certain village, a barber shaves all those who do not shave themselves. Who shaves the barber?
"A little song, a little dance, a little seltzer down your pants"
Chuckles the clown
|
|
|
|
|
The famous Russel's Paradox, from what i remember.
|
|
|
|
|
Behind every paradox lies a Cretan.
Religious freedom is the freedom to say that two plus two make five.
|
|
|
|
|
A rule having no exception: "death and taxes"
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I once discussed that with my religious brother-in-law. He insisted that there are exceptions to that rule. May not to the "taxes" part, though.
Religious freedom is the freedom to say that two plus two make five.
|
|
|
|
|
Amarnath S wrote: Would you agree with this conclusion? If so, is there any example of a rule having no exception?
Agreeing that a proof is valid is not the same as stating that it must be true. Now claiming that it is true could suggest that one should provide the example. Or provide other discussions that would suggest it is true. Or just believe and dispense with the work.
My favorite example with this is geometry (Euclidean) where parallel lines do not intersect. I certainly believe it. And I doubt anyone can provide an example that shows they do intersect. But for that matter they cannot provide an example where they do not intersect either.
|
|
|
|
|
jschell wrote: parallel lines do not intersect
Though I am not a theoretical physicist, have heard that "space is curved", whatever it means. If space is curved, will there be a possibility of parallel lines meeting? Not sure.
|
|
|
|
|
Amarnath S wrote: will there be a possibility of parallel lines meeting
Spherical geometry rather than Euclidian.
But one can also start in on a definition since a line, even theoretical, could still be claimed to be something that must exist in the universe. So if the universe is curved then the line must be as well.
But then what happens with the degrees in a right triangle which can only exist if those lines do not intersect.
|
|
|
|
|
The exception for statement 1 is no exception. Doh
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
You :
does a solution to the Russel Paradox exist
ChatGPT
Yes, several solutions to the Russell Paradox exist, which emerged after Bertrand Russell presented the paradox in 1901. One common solution is to restrict the comprehension principle, which states that for any property, there exists a set of all objects that have that property. By restricting this principle, mathematicians and logicians have been able to formulate set theories, like Zermelo-Fraenkel set theory (ZF) or von Neumann-Bernays-Gödel set theory (NBG), which avoid the paradox by disallowing the formation of certain "self-referential" sets. Another approach is to distinguish between sets and classes, where classes can contain sets but not be sets themselves, thereby sidestepping the contradiction. These solutions have allowed set theory to develop into a foundational framework for mathematics without succumbing to paradoxes like Russell's.
Me : If Statement 2 is a rule it must have an exception.
Conclusions: Statement 1 has no exception. There is at least one rule which has no exception.
|
|
|
|