|
Full question: Should every class have one or more interface base classes which are the only means of accessing that class?
Yes would be my answer! My opinion is that no class should ever keep a direct reference to any other class, they should only ever use interfaces, but I'm having trouble persuading some of my colleagues that this is useful.
Does anyone have a link to a persuasive coding standards style document that explains why this is a good idea?
Does anyone disagree with this opinion?
|
|
|
|
|
LetsMond wrote: Does anyone disagree with this opinion?
Yes, I do. It is in direct conflict with the KISS Principle[^]
That said, I have certainly utilized that type of design to guarantee proper use of an object. You just need to make sure it is required rather than just being an opinion.
|
|
|
|
|
I disagree that following this approach makes things more complicated. You will end up with more code but, looking at any individual class, it makes it much simpler and easier to work out what's going on if you can assume that it will only access other classes via the interfaces it holds and that it will only be accessed via the interfaces it supports.
|
|
|
|
|
LetsMond wrote: I disagree that following this approach makes things more complicated.
Of course it does. OOD is a constant effort to find the optimum balance between the flexibility you need and the simplicity you desire.
Or
You don't add design unless you need it.
Requirements rule.
|
|
|
|
|
This approach should be considered as just another tool in your toolbox.
When you start slavishly following rules laid down by OO gurus instead of considering whether it's appropriate for the circumstance, then you and your colleagues are in for a world of pain.
Remember, most OO gurus spend most of their time writing books and speaking at conferences and don't actually produce much software, so learn what they can teach, but don't get carried away.
David Anton
http://www.tangiblesoftwaresolutions.com
Convert VB to C#, C++, or Java
Convert C# to VB, C++, or Java
Convert C++ to C#, VB, or Java
Convert Java to C#, C++, or VB
|
|
|
|
|
I agree that every case needs to be considered separately when dealing with this type of thing (I'm no OO guru's slave). It's why this is a good idea in principle that I am trying to get across and get agreement on. One can then allow for exceptions and look at individual cases afterwards.
I know I've read convincing information on this before but now I can't find it.
|
|
|
|
|
LetsMond wrote: I know I've read convincing information on this before but now I can't find it.
Have you looked at c2.com[^]? If it is considered a conventional best practice you should be able to find cunningham, fowler or beck talking about it.
Also if you do find it please post back here so we can check it out. Thanks.
|
|
|
|
|
David Anton wrote: Remember, most OO gurus spend most of their time writing books and speaking at conferences and don't actually produce much software
Really? Do you know these guys and therefore know that they don't work on real world production software? The reason I ask is because the information I have seen, at least for some of the industry leaders I refer to, would seem to contradict your statement.
|
|
|
|
|
They might have some good advice (some more so than others - I have many of Beck's books), but what I said was really just a tautology and therefore nothing I can take credit for: if you spend most of your time writing books and speaking at conferences, then you aren't spending most of your time developing software.
David Anton
http://www.tangiblesoftwaresolutions.com
Convert VB to C#, C++, or Java
Convert C# to VB, C++, or Java
Convert C++ to C#, VB, or Java
Convert Java to C#, C++, or VB
|
|
|
|
|
David Anton wrote: if you spend most of your time writing books and speaking at conferences, then you aren't spending most of your time developing software.
So you believe in quantity versus quality? I mean if someone spends any time developing software then some other time writing then they can't know what they are talking about? Perhaps I am completely misunderstanding your statements.
I have not written anything and therefore spent almost all my industry time developing. Even so my experience can't even begin to match the resume of Ward Cunningham[^]
|
|
|
|
|
You asked four questions, my answers are: no, no, no, yes.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Here is the situation.
extern int var1=0;
thread1
{
var1=10;
}
thread2
{
read var1;
}
The above thing is just a scenario. My program is really long to post it here. I need to access the var1 in thread2.
Any suggestions?
Thanks
Niks
modified on Tuesday, June 16, 2009 1:17 PM
|
|
|
|
|
It is hard to answer with the provided information. Is this variable declared inside a class and the methods threads are using is in the same class? If yes, you will have access to the variable. Make sure you use proper synchronization mechanisms if you are writing to a shared variable.
|
|
|
|
|
No, it not defined inside a class. And the method threads are using different classes. My program is a audio and screen recording program. I need to record both of them for the same time and such should pass common parameter 'time' to both the threads which call different classes.
I hope this is clear.
|
|
|
|
|
Variables do not reside in a thread - they reside in memory.
The memory for your process is shared by all threads of that process.
Therefore, you access variables the same way you always do.
As mentioned before, if more than one thread can access a variable
at the same time, you may need to synchronize access to the variable.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
sounds like a weird problem as others have pointed out access should be available to all threads within the scope of a process.
but if for some reason it doesnt work like that maybe you could use PostThreadMessage()???
something like
void MyThread::SyncTimeToThreads(some_time_struct t)
{
...
PostThreadMessage(TheTargetThread,TIME_SYNC_MSG,t,NULL);
PostThreadMessage(TheOtherTargetThread,TIME_SYNC_MSG,t,NULL);
...
}
ugly and not really a good solution, as u should have access to the variable in the context you discribed, so i would hunt around find out why you cant access it normally before considering other options.
|
|
|
|
|
Hi,
I initialized my var1=-1, then changed its value in one thread. I was able to access it in other thread without any problem.
Thank you for trying.
Niks
|
|
|
|
|
I found how to get the index of row in listview when you DoubleClick
this is the code
/////////////////////////////////////////////////////////////////////
String *field1;
int rowvar=1;
field1 = listView1->Items->Item[listView1->FocusedItem->get_Index()]->SubItems->Item[rowvar]->Text;
/////////////////////////////////////////////////////////////////////
This Works very fine, But i need to sort the values in the listview when i click on a column.
any one have idea how to sort by header???
|
|
|
|
|
wael_r wrote: any one have idea how to sort by header?
Look at this article[^]
I assume you will be able to translate the VB,C# sample code to CLI.
|
|
|
|
|
Hey,
When obtaining a key to decrypt a file encrypted using RC4 algorithm, CryptImportKey() fails.
The error says, "Invalid type specified".
What may be the possible reasons for this ?
It fails when I export the key in one application and import it in another application.
Has this something to do with storage of keyBLOB (I store it in a text file while exporting the key and read it from the text file while importing from a different application)?
Or is there some other reason that may lead it to failure.
Please reply at the earliest.....
Regards,
|
|
|
|
|
try to be more specific:
is it a build-time or a run-time problem.
what is the exact message
show some code, and indicate in exactly which line it fails
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Any idea why doesn't this compile?
#include "stdafx.h"
#include <bitset>
#include <iostream>
#include <ctime>
using namespace System;
int main(array<System::String ^> ^args)
{
const int N = 2000000;
clock_t cstart = clock();
bitset<N + 1> b;
int count = 0;
int i;
for (i = 2; i <= N; i++)
b.set(i);
i = 2;
while (i * i <= N)
{
if (b.test(i))
{
count++;
int k = 2 * i;
while (k <= N)
{
b.reset(k);
k += i;
}
}
i++;
}
while (i <= N)
{
if (b.test(i)) count++;
i++;
}
clock_t cend = clock();
double millis = 1000.0 * (cend - cstart) / CLOCKS_PER_SEC;
cout << count << " primes \n" << millis << " milliseconds\n";
return 0;
}
Errors:
Error 4 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 19 SieveOfErathostenes
Error 5 error C2228: left of '.set' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 19 SieveOfErathostenes
Error 6 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 24 SieveOfErathostenes
Error 7 error C2228: left of '.test' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 24 SieveOfErathostenes
Error 8 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 30 SieveOfErathostenes
Error 9 error C2228: left of '.reset' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 30 SieveOfErathostenes
Error 10 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 39 SieveOfErathostenes
Error 11 error C2228: left of '.test' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 39 SieveOfErathostenes
Error 12 error C2065: 'cout' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 46 SieveOfErathostenes
NOTE:
1. Core Java Vol I 8th Ed. Pg. 713 (727)
Jon
|
|
|
|
|
is this the right forum for you?
apart from your Java note, I see code that looks like regular C++, not managed C++/CLI which is the subject of this forum.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
|
jon_80 wrote: That's what I've been told ma'am
Luc is not a female name!
Best Wishes,
-David Delaune
|
|
|
|