Questions tagged [design-principles]

Design principles are ideas that guide developers toward certain goals in software design.

Software has many different desirable quality aspects -- among them are reliability, security, maintainability, efficiency, and size; and these are all impacted by choices made by the developers. Software design principles tend to focus on the maintainability aspects of quality: is the code loosely coupled, or does it have many dependencies that make it hard to use? Is the code highly cohesive, or is a collection of unrelated information needed to use a module? Is the code readable and understandable? Is the code testable? Is the code usable and reusable? Is the code simple or complex?

Various design principles can be used by developers to advise them in making choices that will yield highly cohesive, loosely coupled, simple, maintainable designs. The SOLID design principles are an example of specific design advice for object oriented projects. The Principles of User Interface Design provide design advice for creating user interfaces.

309 questions
1216
votes
35 answers

What is an example of the Liskov Substitution Principle?

I have heard that the Liskov Substitution Principle (LSP) is a fundamental principle of object oriented design. What is it and what are some examples of its use?
560
votes
17 answers

Why Choose Struct Over Class?

Playing around with Swift, coming from a Java background, why would you want to choose a Struct instead of a Class? Seems like they are the same thing, with a Struct offering less functionality. Why choose it then?
bluedevil2k
  • 9,366
  • 8
  • 43
  • 57
71
votes
6 answers

Liskov substitution principle - no overriding/virtual methods?

My understanding of the Liskov substitution principle is that some property of the base class that is true or some implemented behaviour of the base class, should be true for the derived class as well. I guess this would mean when a method is…
60
votes
14 answers

What is the meaning and reasoning behind the Open/Closed Principle?

The Open/Closed Principle states that software entities (classes, modules, etc.) should be open for extension, but closed for modification. What does this mean, and why is it an important principle of good object-oriented design?
47
votes
6 answers

Pipeline design pattern implementation

This is a design question regarding the implementation of a Pipeline. The following is my naive implementation. Interface for individual steps/stages in the pipeline: public interface Step { public U execute(T input); } Concrete…
Prashant Chauhan
  • 570
  • 1
  • 5
  • 14
43
votes
3 answers

What is an example of the Single Responsibility Principle?

Can someone give me an example of the Single Responsibility Principle? I am trying to understand what it means, in practice, for a class to have a single responsibility as I fear I probably break this rule daily.
31
votes
8 answers

Should I favour IEnumerable or Arrays?

In many projects I work on, whenever I have to return a read only collection, I use the IEnumerable interface and make it type specific like so: Public ReadOnly Property GetValues() As IEnumerable(Of Integer) Get 'code to return the…
Alex Essilfie
  • 12,339
  • 9
  • 70
  • 108
29
votes
4 answers

What's the difference between design patterns and design principles?

I'm new to Ruby on Rails, and I went through these articles. Design Patterns in Ruby: Observer, Singleton Design Patterns in Ruby But I couldn't understand the actual difference between design patterns and design principles. Could someone please…
Bibek Sharma
  • 3,210
  • 6
  • 42
  • 64
27
votes
7 answers

What is the reasoning behind the Interface Segregation Principle?

The Interface Segregation Principle (ISP) says that many client specific interfaces are better than one general purpose interface. Why is this important?
26
votes
2 answers

Design Patterns for Multithreading

Multitasking seems to be a disaster at times when big projects crashes due to shared mutation of I would say shared resources are accessed by multiple threads. It becomes very difficult to debug and trace the origin of bug and what is causing it. It…
17
votes
7 answers

Calling the variable property directly vs getter/setters - OOP Design

I know this is probably subjective but I read this optimization page from Google for PHP and they suggest use the variable property directly without the need of getters and setters. Understandably I see the performance gain in this but is this…
Phill Pafford
  • 83,471
  • 91
  • 263
  • 383
17
votes
4 answers

SOLID principles implementation for C

I know SOLID principles were written for object oriented languages. I found in the book: "Test driven development for embedded C" by Robert Martin, the following sentence in the last chapter of the book: "Applying the Open-Closed Principle and the…
Oscar Castiblanco
  • 1,626
  • 14
  • 31
16
votes
4 answers

Const reference field as readonly property in C++ class

Is it good to use a const reference field as a readonly getter in C++ classes? I mean, does this code meet good practices? class check{ private: int _x; public: const int& x = _x; void setX(int v){ _x = v; } }; It is working…
16
votes
4 answers

What's the difference between principles YAGNI and KISS?

Obviously there are syntactical differences between YAGNI and KISS but I can't see any semantic differences between them. Are they really in essence just the same thing?
Mr Grok
  • 3,876
  • 5
  • 31
  • 40
15
votes
3 answers

Does Scala's pattern matching violate the Open/Closed Principle?

If I add a new case class, does that mean I need to search through all of the pattern matching code and find out where the new class needs to be handled? I've been learning the language recently, and as I read about some of the arguments for and…
Jeff
  • 14,831
  • 15
  • 49
  • 59
1
2 3
20 21