solid-principles

SQLAlchemy: Knowing the field names and values of a model object?

走远了吗. 提交于 2019-12-04 10:29:26
I'm trying to keep to SOLID object oriented programming principles, stay DRY, etc, but my newness to Python/SQLAlchemy/Pyramid is making it very hard. I'm trying to take what I now know to be a SQLAlchemy model used to create a simple Pyramid Framework object and use what I know to be "reflection" in C#, it may be called something different in Python (Introspection? Not sure as this is only my second week with python but I have lots of experience in other languages (C/C++/C#,Java, etc) so the trouble seems to be mapping my knowledge to the vocabulary of python, sorry), to find out the field

Does implementing multiple interfaces violate Single Responsibility Principle?

僤鯓⒐⒋嵵緔 提交于 2019-12-04 10:26:31
问题 From Wikipedia: Single responsibility principle states that every class should have a single responsibility, and that responsibility should be entirely encapsulated by the class. Does that mean implementing multiple interfaces violates this principle? 回答1: I would say not by itself. A class can have one responsibility, but do multiple things in the process, and implement one interface for each set of things it needs to do to fulfill its responsibility. Also, interfaces in Java can be used to

Simple Factory vs Factory Method: Switch statement in factory vs. client

好久不见. 提交于 2019-12-04 08:16:35
I understand that one of the main advantages of the Factory Method over Simple Factory is that it doesn't violate the Open-Closed SOLID Principle. That is, the former doesn't require modifying the switch statement when new types are added. There is one piece on which I am hoping to get clarification. If I were to use a simple factory, I would have a factory like this (simplified): public class ObjectFactory { public static IObject CreateObject(ObjectTypeEnum objectType) { switch (objectType) { case TypeA: return ObjectA; break; case TypeB: return ObjectB; break; case TypeC: return ObjectC;

Writing JavaScript according to SOLID

柔情痞子 提交于 2019-12-04 07:27:16
问题 Have any one used the SOLID programming principle (or any of it's parts) while developing JavaScript? I've just started up on reading on it but can't seem to find anyone that used it for JS. The only part I find easy to implement/use is the "Single responsibility principle". What I'm looking for is articles or example where these principles are used. And are there any argument's why one shouldn't use some parts? For example the "Interface segregation principle" says that "the notion that many

Patterns to implement SOLID principles

余生颓废 提交于 2019-12-03 13:23:20
问题 I'm doing a presentation of SOLID design principles and I'm trying to connect the Single Responsibility Principle and the Open-Closed principle to design patterns. Currently I have SRP: proxy, façade OCP: strategy, command Are there any other basic patterns I should include? 回答1: The SOLID principles are more attributes of a good OO language and framework than anything else. They don't handily translate into design patterns. Rather, they influence good vs. bad in a design pattern. Generally,

DDD: What kinds of behavior should I put on a domain entity?

南楼画角 提交于 2019-12-03 10:10:11
My team tries very hard to stick to Domain Driven Design as an architectural strategy. But, most of the time, our domain entities are pretty enimic. We'd like to be putting more business/domain behavior on our domain entities. For example, Active Record puts data access on the entity. We don't want that because we happily use the repository pattern for data access. Also, we design our software to be SOLID (the five software design principles that Uncle Bob put together). So, it's important to us that we pay attention to single responsibility, open-closed, liskov, interface segregation, and

How does the SOLID open/closed principle fit in with Dependency Injection and dependency inversion

北城余情 提交于 2019-12-03 10:04:06
I am starting to apply SOLID principles, and am finding them slightly contradictory. My issue is as follows: My understanding of dependency inversion principle is that classes should depend on abstractions. In practice this means classes should be derived from interfaces. All fine so far. Next my understanding of the open/closed principle is that after a certain cut off point, you should not alter the contents of a class, but should extend and override. This makes sense so far to me. So given the above, I would end up with something like this: public interface IAbstraction { string method1(int

When adhering to Liskov Substitution Principle (LSP) can a child class implement additional interface?

强颜欢笑 提交于 2019-12-03 09:54:35
Consider this ruby example class Animal def walk # In our universe all animals walk, even whales puts "walking" end def run # Implementing to conform to LSP, even though only some animals run raise NotImplementedError end end class Cat < Animal def run # Dogs run differently, and Whales, can't run at all puts "running like a cat" end def sneer_majesticly # Only cats can do this. puts "meh" end end Does method sneer_majesticly violate LSP, being defined only on Cat, since this interfaces is not implemented nor needed on Animal? The Liskov Substitution Principle has nothing to do with classes.

Confused about Single Responsibility Principle in the following example

痞子三分冷 提交于 2019-12-03 07:38:08
In the following video , the author takes an existing class and assigns the Single Responsibility Principle to it. He takes a Print Class that has the job of Accessing Data, Formatting, and Printing the report. He breaks up each method to its own class, so he creates a DataAccess class to handle data access, he creates a ReportFormatter class to handle the formatting of the Report, and he creates a ReportPrinter class to handle the printing of the Report. The original Report class is then left with one method, Print() which calls the ReportPrinter's class method Print. DataAccess and

Using the “Single Responsibility Principle” forces my containers to have public setters

雨燕双飞 提交于 2019-12-03 07:03:16
I'm trying hard to design following the SOLID principles. What I've found is that when you use the "Single Responsibility Principle" (the S of SOLID) you usually have to split classes between the data containers and the data processors. For example If I have a class person with 5 properties that is read from DB instead of putting everything inside a class I create a Person class with the properties and another PersonReader class that reads that information from the database and creates the Person. If I do that I have to open the Person properties so PersonReader could access them but then I