|
|
Okay, so I'm going through some code (off codeproject), which is always interesting, since you see so many different styles. One piece of code had a class within a class, I suppose forcing only one user of the internal class. I don't even know if I'm using the correct terminology, so bear with me.
I come from the school of development where one .cpp and one .h file defines one class. I've seen others have a utility.cpp/h file with multiple classes in it. In the past, this arrangement made it difficult to find things, but I suppose with the advent of code browsers, the issue is more subdued. However, in keeping with the one class / one file appproach, I tend to code my applications centered around dialogs or views or etc... standard mfc stuff. I doubt I'm the only one.
So, in real application development, some of these dialog/view classes can get huge. Due to the nature of my application, I am heavily dialog centric, so most of my application classes inherit from CDialog, etc. The data and processing associated with this dialog processing is heavily coupled to the dialog and usually is not used outside of the dialog. There are some obvious exceptions, and these go off into their own classes. Which brings me to my point....
Some of my dialog classes are large. Managing the data within it would lend itself to a class unto itself for the simple reason of enforcing discipline - the code can easily degrade to spaghetti land. But, I really don't want to break out the data (I guess we're talking business objects in a very distorted way) in a class, viewable across the project, when this class is only going to be used within another class.
How do you deal with this design issue? Inquiring minds want to know
Thanks
Charlie Gilley
Will program for food...
Whoever said children were cheaper by the dozen... lied.
My son's PDA is an M249 SAW.
My other son commutes in an M1A2 Abrams
|
|
|
|
|
charlieg wrote: But, I really don't want to break out the data
charlieg wrote: How do you deal with this design issue? Inquiring minds want to know
Model-View-Controller[^]
led mike
|
|
|
|
|
Mike,
Excellent suggestion. but... maybe I'm making a mountain out of a mole hill, but my point is that this document only makes sense within the context of the dialog class. If I break out the 'document' into a separate class, I now have a cpp/h file that just broadcasts "use me".... argh... i know I've read about this before. In my sleep deprived state, the term slipped my brain - I want something like an anonymous class from Java land....
<oops> just read about anonymous C++ classes - not what I Want. I want a class that has only local scope. Hmm.. I am rambling bad
chg
Charlie Gilley
Will program for food...
Whoever said children were cheaper by the dozen... lied.
My son's PDA is an M249 SAW.
My other son commutes in an M1A2 Abrams
|
|
|
|
|
Design Patterns (MVC is one of them) simplify things. Don't fight it, just do it.
charlieg wrote: The data and processing associated with this dialog processing is heavily coupled to the dialog
Yeah, tight coupling is "not good". MVC avoids it, get with it or continue to deal with the same coupling issues over and over again. It is an easy call.
led mike
|
|
|
|
|
You could have a class in a separate h+cpp pair, but only #include it in the dialog header. The only instance of this class would then be a member variable inside the dialog class. This would make sure no other code uses it. If you want to go further, the business logic class could have a private constructor, and the dialog class declared as friend - another step towards not letting any other code use the business logic class.
If you're really fond of patterns, you could also make a class factory for the business logic class. See: http://en.wikipedia.org/wiki/Abstract_factory_pattern
Hope this helps.
Denis
|
|
|
|
|
mike & all - thanks for the suggestions.. will look at religiously applying mvc and other patterns.
Charlie Gilley
Will program for food...
Whoever said children were cheaper by the dozen... lied.
My son's PDA is an M249 SAW.
My other son commutes in an M1A2 Abrams
|
|
|
|
|
Hello everyone,
As I am new in this area I have few silly questions. What is the difference between Visual C++, Visual Basic, Visual C#?!!! I have been reading and learing about them and so far followed some simple tutorials to create window application (Simple Ones ofcourse! Much more compplicated then "Hello Word" ofcourse!). But I am unable to see much of differences on what is finnaly created.
Although I should say I like Visual C# enviroment Better! But that could be the result of the fact that I started from Visual C#!
Can someone be kind enough to take a moment and lead this confused indivitual?
Thanx so much for your help and have a great day.
Khoramdin
-- modified at 15:48 Tuesday 30th January, 2007
|
|
|
|
|
|
Khoramdin wrote: But I am unable to see much of differences on what is finnaly created.
The point is that there is no difference, they each create an exe which does the same thing, especially in console mode.
VB.NET is probably easiest, C++ is hardest. C++ is the most powerful, and C# provides the best framework for you to start learning, and move to c++ later if you want to.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Hello Christian,
After spending hours and playing around with Visual C++, Visual Basic, and Visual C#, I would like to say you are 100% right.
May I ask you if you know of any good book, online tutorial or even Video Tutorial which I comit myself to in order to advance in Visual C# and Visual C++?
Thank you for the help and have a great day.
Khoramdin
|
|
|
|
|
I'm sorry, I really don't know. I worked through C# books from the level of an experienced C++ coder, so I can't really suggest any beginner books, but I would certainly advocate C# over C++ as a starting point.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
I am creating a log file and writing to it in a function called WriteToLog. I am creating the file using CreateFile and writing to it using WriteFile. The problem is the filepointer is not moving and always I have only 1 sentence in my logfile, its just overwriting the file and even though I write lot of sentences into my logfile. I just see the last sentence that I wrote to it.
Any help greatly appreciated.
Thanks
Sai.
VOID WriteToLog(LPCTSTR lpszFormat, ...)
{
CString csT1,csT2;
va_list args;
BOOL bRet=FALSE;
HANDLE hFile=NULL;
SYSTEMTIME stTime;
DWORD dwT1=0;
va_start(args, lpszFormat);
csT1.FormatV(lpszFormat,args);
va_end(args);
CSingleLock oLockcopyCounter(&g_oMessageOutputSection);
oLockcopyCounter.Lock();
GetLocalTime(&stTime);
csT2.Format("%s[0x%x] %02d/%02d/%04d %02d:%02d:%02d.%03d: %s", "\r\n",GetCurrentThreadId(),stTime.wMonth, stTime.wDay,
stTime.wYear, stTime.wHour, stTime.wMinute, stTime.wSecond, stTime.wMilliseconds,(PCHAR)(LPCTSTR)csT1);
hFile=CreateFile(g_szLogFileName,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if(hFile!=INVALID_HANDLE_VALUE)
{
if(GetFileSize(hFile,NULL)> (5*1024*1024))
{
CloseHandle(hFile);DeleteFile(g_szLogFileName);
ReportAsEvent(EVENTLOG_INFORMATION_TYPE,0,"Deleting File %s since it croseed 5 MB Limit",g_szLogFileName);
hFile=CreateFile(g_szLogFileName,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
}
if(hFile!=INVALID_HANDLE_VALUE)
{
WriteFile(hFile,csT2,csT2.GetLength(),&dwT1,NULL);
WriteFile(hFile,csT2,csT2.GetLength(),&dwT1,NULL);
CloseHandle(hFile);
}
else
ReportAsEvent(EVENTLOG_ERROR_TYPE,0,"Creating File %s FAILED. Error %d",g_szLogFileName,GetLastError());
}
oLockcopyCounter.Unlock();
}
|
|
|
|
|
TurboNext wrote: The problem is the filepointer is not moving...
If you want the file to be appended to, you must call SetFilePointer() after opening it.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Maybe try
...
hFile=CreateFile(g_szLogFileName,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
}
if(hFile!=INVALID_HANDLE_VALUE)
{
SetFilePointer(hFile, 0L, 0L, FILE_END);
WriteFile(hFile,csT2,csT2.GetLength(),&dwT1,NULL);
|
|
|
|
|
Thank you guys, It works now. I used SetFilePointer() and its working not. Thanks a lot.
|
|
|
|
|
Hi
I'm working in a simple mail encryption system with random generated passwords.
What I would like is to make some kind of encoding to the password in order to allow the user to share the password via phone.
I tried replacing every char in the pass by its hexa ascii code, but the resulting number is too long, I'm using 32 chars keys.
Any ideas on how could I solve this problem?
Thanks a lot
|
|
|
|
|
Kharfax wrote: What I would like is to make some kind of encoding to the password in order to allow the user to share the password via phone.
You must be a very paranoid individual !!
on a more serious note :
I'm not certain exactly what you really want to do ? you want to encrypt the password a second time to be able to give it more securly ? and send them another key to decrypt that first key ?
me think that you could make your password longer and/or use a better encrytion algo. in your software to validate that license key.
|
|
|
|
|
noooooooo, I'm not paranoid, I use PGP with 1024 bit keys just to be 133t
I just needed something to make easier to the user the task of sharing passwords via phone.
Lets supose the pass is "a&RT2"/(=fbTR16bJ" is really hard to say all that by phone, the idea is to transform that in something like "LU8C-RA7Z-12MVR-97YB" thats a lot easier to tell.
I already found the answer to my problems, and is called Base32.
Thanks a lot for the feedback anyway Maximilien
|
|
|
|
|
|
Hey thanks a lot for the links
|
|
|
|
|
Has anybody experienced any problems after building a release on vista and running it on XP?
I like all my projects to be backward compatible with win98, but my latest build ( on vista ) refuses to even run on XP, giving me a "This is not a valid exe" error.
Before I go pulling my code apart line by line ( which is already full of error checking ) would anybody like to advice me of some of the common problems of backwards compatibility and where I should look first.
|
|
|
|
|
Not me, I've never heard of a "this is not a valid exe" error. That sounds like something the loader would show, which makes me suspect that the file got corrupted.
|
|
|
|
|
I'm beginning to suspect the error is valid. The file has not been corrupted, I copy from the vista machine to the XP machine via a USB pen, and I have done this quite a few times. I have also put a few MessageBox alerts in error prone places, but none of them are being triggered.
You'll have to forgive my translation of the error, the XP machine is a Chinese version, and Chinese isn't exactly my first language. But thats more or less what it say's.
|
|
|
|
|
hi
this is a common error that occurs in XP.
It occurs sometimes when u run exes from the Explorer in XP.
try it in command prompt or just restart.
thx Slipnit
|
|
|
|
|