New answers tagged

3

First I think that is important to redefine the SRP principle for better understanding. Robert C. Martin defines responsibility as a reason to change, so a class should've just one reason to change. In my humble opinion a controller should only care about receiving the request then hand that input over to the service or services that handle the logic and ...


2

I've read answer by @user673679 and just want address a few issues. I strongly disagree with disabling default constructors in classes like Member/Date/BookItem. If class has no default constructor then using it with std::vector, std::map and other template containers becomes very awkward in general. So it is a bad advise. Instead you should make default ...


4

Date: Date.hh is missing some includes (<iostream>, <string>). Don't supply a default constructor. It doesn't make sense to have a default date. Don't supply one- and two-argument constructors. Specifying a month and date in 1970 is unlikely to be very common. We should support years before 1970. There were books back then! year should be a ...


3

I think you're thinking of this backwards. The point isn't that you need to define special subclasses to use the factory method. Rather, when you need to define special subclasses containing their own complex functionality, then you use the factory method. From the Gang of Four: Use the Factory Method pattern when a class can't anticipate the class of ...


4

Don't hide pointers Don't hide pointers in a typedef: typedef struct moduleIF_CTX *moduleIF_CTX_t; This makes it really hard to spot when things are passed by value or by pointer in the rest of the code. You could make it more explicit: typedef struct moduleIF_CTX *moduleIF_CTX_ptr_t; But I would just do this: typedef struct moduleIF_CTX moduleIF_CTX; Yes,...


3

Only the Character and WeaponBehaviour classes are actually useful and neither of them needs to inherit anything. The rest can be just factory functions, because only the constructors differ. If a class constructor does anything except assign arguments to properties, it is probably wrong. Strategy pattern is based on composition rather then inheritance. ...


3

Bug: no assignment when calling filter There are places where Array.filter() is called but not assigned to anything. Array.from(links).filter(link => Scraper.internalLinks.add(link.getAttribute('href'))); and this in addEmails() Array.from(emailsInDom).filter(el => { if(el !== null) { el.filter(el => this.emails.add(el)) } }); ...


4

I choose to focus on the Single Responsibility Principle in this answer. To move closer to the Single Responsibility Principle, I think some of the functionality needs to be moved around. I have decomposed the class and removed all state that is shared on the class (rhetorical question: is the class responsible for state or functionality? If it is "both&...


1

I don't think the generator should inherit from the solver. Rather, any methods that they both need could be moved into a third class that either 1) they both inherit from or 2) they both include as a member. I would try to do #2.


2

If I understand your intent and code properly then you rather have an abstract factory implementation than a factory method pattern implementation. The Abstract Factory pattern, a class delegates the responsibility of object instantiation to another object via composition. The Factory Method pattern uses inheritance and relies on a subclass to handle the ...


Top 50 recent answers are included