design-patterns

How to decouple a class from it's attributes when the methods of the attributes need to modify state of the owning class?

给你一囗甜甜゛ 提交于 2021-01-29 15:38:01
问题 How do I decouple a class from its attributes when methods of the attributes need to modify the state of the owning class? Alternatively, how can I redesign the architecture so that this isn't a problem? This question is a bit abstract, but I keep coming across this problem time and time again. I spend a lot of time designing my code base so that my classes are "high cohesion and low coupling", but then as the code evolves over time, they end up becoming more closely coupled. I'll give the

Is the observer object oriented design pattern just a form of implementing a callback?

萝らか妹 提交于 2021-01-29 11:07:17
问题 I was recently asked what is the difference between a callback and an observer in the Observer OO design pattern. My understanding is that callback is any executable code passed as an argument to a function which is called when a specific event happens. It may be implemented in different forms in different programming languages, such as function pointers, anonymous functions and observers/listeners in the object-oriented paradigm. Developers usually implement callback registration

Acyclic Visitor C++

此生再无相见时 提交于 2021-01-29 04:13:05
问题 I'm reading the book by Alexandrescu, and I've run into the Acyclic Visitor pattern. I think that it's possible to get rid of the macross that calls AcceptImpl method of the BaseVisitable class. Could you tell me, whether the following implementation bellow conforms the standard? class BaseVisitor { public: virtual ~BaseVisitor() {} }; template <class SpecificVisitable> class SpecificVisitor { public: virtual void Visit(SpecificVisitable& t) = 0; protected: ~SpecificVisitor() {} }; template

What is the difference between the CoR and the Decorator? Why is CoR a behavioral pattern? Why is Decorator a structural pattern?

耗尽温柔 提交于 2021-01-28 19:27:20
问题 This answer almost describes the first half of the question. It says: After reading the Gang of Four definitions, I'm not convinced there's a real difference. (included for convenience) Decorator: Allows for the dynamic wrapping of objects in order to modify their existing responsibilities and behaviours Chain of Responsibility: Gives more than one object an opportunity to handle a request by linking receiving objects together Wikipedia fleshes them out a little, but some of it's kinda

Is the facade design pattern only concerned with classes/modules or actual API calls too?

房东的猫 提交于 2021-01-28 14:00:51
问题 I think I understand the purpose of the facade design pattern- to provide an interface to a client that simplifies and abstracts a complex system allowing them to more easily perform a specific task. but the first thing I think of is a microservices style system that has many apis with each having a specific purpose and functionality. If I create another API (microservice) that makes calls on behalf of the client to a couple of the other APIs and abstracts the multiple APIs calls to just one

Is the facade design pattern only concerned with classes/modules or actual API calls too?

和自甴很熟 提交于 2021-01-28 13:58:40
问题 I think I understand the purpose of the facade design pattern- to provide an interface to a client that simplifies and abstracts a complex system allowing them to more easily perform a specific task. but the first thing I think of is a microservices style system that has many apis with each having a specific purpose and functionality. If I create another API (microservice) that makes calls on behalf of the client to a couple of the other APIs and abstracts the multiple APIs calls to just one

Observer pattern: observe attributes independently

青春壹個敷衍的年華 提交于 2021-01-28 07:32:29
问题 I would like to ask how I should correctly implement observer pattern when I need to achieve something like this: WeatherStation[temperature, humidity ...] and I need to be able to "observe" each attribute independently. So when temperature changes only temperature observers will be notified, when humidity changes only humidity subscribers will be notified. My idea was that I would create some classes like ObservableTemperature and interface TemperatureObserver but I this way I would have to

Observer pattern: observe attributes independently

半城伤御伤魂 提交于 2021-01-28 07:18:28
问题 I would like to ask how I should correctly implement observer pattern when I need to achieve something like this: WeatherStation[temperature, humidity ...] and I need to be able to "observe" each attribute independently. So when temperature changes only temperature observers will be notified, when humidity changes only humidity subscribers will be notified. My idea was that I would create some classes like ObservableTemperature and interface TemperatureObserver but I this way I would have to

Helper classes with only public static methods [closed]

折月煮酒 提交于 2021-01-28 06:02:37
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . Improve this question I wish to create a helper class with public static methods only. I declare a class instead of namespace, because I will befriend this class with others so that it can operate on their private members as well. Is this considered a bad OOP practice? Is there an

Why not to code in one class? [closed]

萝らか妹 提交于 2021-01-28 04:43:10
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . Improve this question Right now I am studying design Pattern, and I was wandering about the following... why not to code all my methods in 1 class, each method perform 1 task, so my client can access all the methods from within 1 file and I dont need to create new classes and