I focus here on my vision of its implementation. It is not for me to say if the singleton is a good or bad design pattern. Unfortunately, the singleton is also very often misused, and many articles can be found on the Internet presenting arguments against the singleton. The singleton is also very often used in the implementation of other design patterns.īesides, the singleton makes it possible to maintain a global state without going through a global variable and saves time and allocation space. The singleton is used when you need to have the same object to perform specific actions. This is one of the most straightforward patterns, and it aims to ensure that there is only one instance of a given class. The singleton is a member of the creational patterns. Behavioral patterns - these are the design patterns that deal with the communication and behavior of objects.īut we can still hear about concurrency patterns or even anti-patterns.Structural patterns - these are the design patterns that deal with the relationships between software entities.Creational patterns - these are the design patterns that deal with the creation of objects, which requires particular control.There exist abounding design patterns, and most of the time, we think first and foremost of the GoF design patterns.ĭesign patterns can be split into different categories, in simple words: In software engineering, design patterns are software bricks, recognized as good practice, and addressing common design issues. … And much more than I have not yet had the opportunity to read ….Design Patterns: Elements of Reusable Object-Oriented Software.Here is a non-exhaustive list of resources among my favorite blogs and sites, as well as some books I have read, which I find appropriate for this article.Īll these resources are much more professional and educational than my work, and I highly recommend them if you want to go further. I rewrote a singleton in much the same way as I did in my framework, making sure to make it thread-safe. The singleton part was at the simulation components level.Using a simulation framework distributed between my components, I did not need to make sure my implementation was thread-safe.I implemented a distributed simulation framework in C++11, in which I made extensive use of design patterns.īy the greatest coincidence, I had made in this framework a similar Logger class to trace the execution of simulation components. This question was particularly inspiring to me. The use of C++11 and a thread-safe implementation will be appreciated. The Logger should have a print method taking as input a log level (INFO, WARN, ERROR), and a message. Implement a Logger, based on the singleton. One of the questions in my test was, from memory: If by any chance you are interested in my vision, and you identify gaps in my proposals, I would be particularly glad to discuss this in the comments. I prepared a small related work section in this article.Īnyway, I think it’s time for me to stop hiding behind the excuse that someone somewhere must have already done better not to publish. My contribution on this blog is particularly minimal, and I’m sure that some books I don’t have yet offer even better implementation methods than mine.įurthermore, some C++ blogs are way more interesting than mine. I, therefore, take this opportunity to express my point of view on modern design in C++. Nevertheless, once the test was over, I took my books on the C++ language to check my answers, and I noticed that most of them were rather old-school on their recommendation for design patterns implementation. Latterly, I participated in a test, during which I had a few tens of minutes to answer questions about implementation in modern C++.įrom my point of view, I had no difficulty answering the questions, and to be honest, I even had much fun. thesis, and I have started my job search process. I am now a reasonably experienced engineer, I have worked on stimulating projects at Thales and Airbus in France, and I want to share some visions I have on my field. Table of Contentsįirst of all, pardon my French, I am a French native speaker with a fairly solid background in English, and some of my sentences may seem flawed.įor a few years now, I’ve been thinking about maintaining a blog on programming. Modern C++ best practices allows an explicit and beautiful implementation of the singleton design pattern.Ĭode source of the full example available on hnrck/singleton_example.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |