It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am from JAVA so please please guide me if i am wrong.
In Java we mostly use a singleton class and create all the class objects thought the singleton class.
What about in c++?
I know we can use singleton but mostly while going through most of the stack overflow questions. Most of them says it's not good to use singleton in c++
Can you recommend some book or some project which will be easy to understand?
Whether you're writing in C++ or Java singletons have many, bad implications.
They make it very difficult to test as their static nature preculdes late binding to, say, sway a real database with a stub that's quicker and has fewer depencies.
They also provide a fig leaf for global variables, trying to make them masquerade as a good design decision. Take a look at the alternatives, it'll pay off in a better design. You may want to look into dependency injection for ways to design a more testable system without singletons.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
What does it mean "register a class", if we are talking about C++ and OOP, not about register, COM or some other libraries?
In the context of pure C++, without respect to any specific platoform or library, "register a class" has no meaning. This is not a language concept, nor is it any design pattern I am aware of.
It does however have at least two meanings the Windows world. For posterity and future readers:
You can register a Window class. A Window class contains some basic functionality and other parameters that effect how specific windows behave on-screen.
You can register a COM class so that specific instances of that COM class can be instantiated by clients.
"context was in articles about OOD, and it was said something like it is good practice to plan your classes in the way that for changing some aspect of program it will be enough to write new class, register it and you get new staff"
Now it seems to me you are talking about the publisher/subscriber pattern. It allows loose coupling between caller and callee.
You can find a C++ implementation everywhere, in the GoF book, or here:
http://rtmatheson.com/2010/03/working-on-the-subject-observer-pattern/
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Here's the problem: I'm developing a framework (CLCuda, not the most creative name out there) where the programmer instantiates one object, and depending on what the system supports (CUDA or AMD OpenCL), will use the corresponding methods, without having to change any line of code to that.
I have a abstract class named CLCuda (pure virtual methods, but could be just virtual), and the two classes that implement its methods are CLCudaCUDA and CLCudaOPENCL.
I wanted to have something like this: instantiate one object that will iniciatlizate CUDA or OpenCL, depending on what graphics card the user have, that can access the methods of the available platform (through the class CLCudaCUDA or CLCudaOPENCL).
I already coded the methods of CLCudaOpenCL and CLCudaCUDA (hard times doing that), so my problem is with OOP.
How could I structure my classes?
If anyone can help... thanks very much!
Your problem seems to suggest a "Factory" design pattern. Presumably you have a method to determine which is supported on the current host, so you should leverage that in the implementation of your factory.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I've read a lot of good things written about design patterns but am yet to actually look at things in detail. To me, design patterns is just a fancy name for data structures and algorithms. Before I invest any time in more reading, I'd like to see some good examples of design patterns working in real life.
What good examples of design patterns can I find in well-known open source projects?
C++ preferred.
Update: I see the close votes and downvotes. These were expected. If there is an alternative post with answers to my question, please lead me to it. At least leave a reason as to why this post doesn't belong here.
It appears you did not invest enough time into design patterns to truly grasp what they are. I encourage you to read more, because design patterns are not a fancy name for data structures and algorithms; there is barely any link between algorithms and design patterns. Design patterns are "recipes" that help you organize classes and their relationships in a way that makes them easier to reuse.
As for examples, no need to look very far: the STL collection iterators are implementations of the iterator pattern.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
When reading the documentation of one or another boost library, I encountered some statements giving a hint that the virtual keyword is kind of evil. See http://www.boost.org/doc/libs/1_46_1/libs/msm/doc/HTML/ch03s05.html, for example:
It will not be said that MSM forces the virtual keyword down your throat!
According to http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20.4, the virtual keyword is really not that bad, and my feeling about it is the same.
Why do some of the boost people regard virtual function calls as the worst thing ever? I have the impression that the boost guys are really the experts on C++, so there must be something about it.
there is case where static polymorphism is preferred to dynamic one. That's what Christophe states here. Nothing more.
Runtime polymorphism has an extra cost, namely the vtable. Once the vtable is added in a type, it can't be removed. One of the core strengths of C++ is that "you only pay for what you use". Therefore, to keep objects as lean as possible, several libraries avoid virtual functions when possible. Not because it is evil, but because you may not want it.
I think the inference is that MSM does not, through its inner workings or structure, force you to declare members of your own code as virtual, or to override theirs. There are libraries that require this, for instance libraries that dynamically create "proxies" of your classes such as mocks or lazy-loaders.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I need to implement a simple text encryption in C++ without using any existing framworks. This is purely for educational purpose to learn the in-and-outs and to learn the way to implement such a system. I am not planning to implement this in production code. I can use Windows APIs but it won't be cross platform. I am trying to learn something can work across multiple platforms. the best way to implement this is implement using C/C++. Please share good resources or links in this regard.
Depending on what you actually want, you could look at the CipherSaber project: instructions to implement your own RC4 encryption code for a simple IV+text format.
However this is an academic exercise only: you should never use your own crypto code in production unless you really know what you're doing. You could also read Schneier's Applied Cryptography for a good introduction to all of this stuff.