design-patterns

Can a [GoF]-ConcreteSubject override the notify method?

本秂侑毒 提交于 2020-07-21 03:36:13
问题 I'm modelling a situation in wich there are: NotificationBox : the observer list1 , list2 , list3 : the subjects now I would make a piece of diagram in wich using observer pattern describe the fact that each list implement different type of notify() (for example some change in the state of a list need to be notified only to some observer, with some criterion) I made something like: in this case each subject override the notify method in order to notify only some subset of observer depend on

CQRS: Command Return Values [closed]

旧城冷巷雨未停 提交于 2020-07-16 11:00:07
问题 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 2 years ago . Improve this question There seems to be endless confusion about whether commands should or should not have return values. I would like to know if the confusion is simply because the participants have not stated their context or circumstances. The Confusion Here are examples

How does it work: passing an abstract class as parameter in Room Database builder

蓝咒 提交于 2020-07-09 08:23:49
问题 I have seen this implementation in Room database. There is an abstract class AppDatabase - @Database(entities = {Task.class}, version = 1) public abstract class AppDatabase extends RoomDatabase { public abstract TaskDao taskDao(); } But when you create an Object of this AppDatabase class, you do something like this - AppDatabase appDatabase = Room.databaseBuilder(context, AppDatabase.class, "something").build(); My questions are - How can you pass an Abstract class directly like this without

How does Pattern Matching in Scala overcome duplication that switch case causes?

こ雲淡風輕ζ 提交于 2020-07-04 10:08:12
问题 NOTE: I am asking this question out of inquisitiveness and not questioning the importance of a language feature. Looks to be a great feature introduced to people from imperative world of programming. I am new to Scala and still trying to figure out where all, do its massive sets of constructs fit in and can be leveraged. Pattern matching can definitely do stuff 100 x better than the switch case. but still, it is a case construct over which we use to prefer polymorphism since the time OOP came

How does Pattern Matching in Scala overcome duplication that switch case causes?

给你一囗甜甜゛ 提交于 2020-07-04 10:05:32
问题 NOTE: I am asking this question out of inquisitiveness and not questioning the importance of a language feature. Looks to be a great feature introduced to people from imperative world of programming. I am new to Scala and still trying to figure out where all, do its massive sets of constructs fit in and can be leveraged. Pattern matching can definitely do stuff 100 x better than the switch case. but still, it is a case construct over which we use to prefer polymorphism since the time OOP came

Strategy or Command pattern?

纵饮孤独 提交于 2020-06-24 14:47:32
问题 Assuming I have a list of financial transactions, I have a need to execute a list of validation rules against those transactions. An example would be I have a transaction to purchase a product, however first I need to validate that the account in the transaction has enough available funds, that the product is not sold out etc. As a result of these many rules the transaction will be marked as rejected, as well as an error code should be specified. Naturally I am thinking towards fronting my

In SOLID, what is the distinction between SRP and ISP? (Single Responsibility Principle and Interface Segregation Principle)

一世执手 提交于 2020-06-24 04:56:09
问题 How does the SOLID "Interface Segregation Principle" differ from "Single Responsibility Principle"? The Wikipedia entry for SOLID says that ISP splits interfaces which are very large into smaller and more specific ones so that clients will only have to know about the methods that are of interest to them However, to me that sounds like just applying the SRP to interfaces as well as classes. After all, if an interface is only responsible for just one conceptual thing, than you wouldn't be able

Policy based design and best practices - C++

允我心安 提交于 2020-06-23 22:26:09
问题 struct InkPen { void Write() { this->WriteImplementation(); } void WriteImplementation() { std::cout << "Writing using a inkpen" << std::endl; } }; struct BoldPen { void Write() { std::cout << "Writing using a boldpen" << std::endl; } }; template<class PenType> class Writer : public PenType { public: void StartWriting() { PenType::Write(); } }; int main() { Writer<InkPen> writer; writer.StartWriting(); Writer<BoldPen> writer1; writer1.StartWriting(); return 0; } I wrote the above code as part

Pluggable Adapter as mentioned in the GOF

自作多情 提交于 2020-06-16 01:33:12
问题 The related Posts on Stackover flow for this topic : Post_1 and Post_2 Above posts are good but still I could not get answer to my confusion, hence I am putting it as a new post here. MY Questions based on the GOF's Elements of Reusable Object-Oriented Software book content about Pluggable Adapters (mentioned after questions below), hence I would appreciate if the discussions/answers/comments are more focused on the existing examples from GOF regarding the pluggable Adapters rather than other

Pluggable Adapter as mentioned in the GOF

僤鯓⒐⒋嵵緔 提交于 2020-06-16 01:33:11
问题 The related Posts on Stackover flow for this topic : Post_1 and Post_2 Above posts are good but still I could not get answer to my confusion, hence I am putting it as a new post here. MY Questions based on the GOF's Elements of Reusable Object-Oriented Software book content about Pluggable Adapters (mentioned after questions below), hence I would appreciate if the discussions/answers/comments are more focused on the existing examples from GOF regarding the pluggable Adapters rather than other