Questions tagged [design-principles]

68 questions
80
votes
2 answers

Are there any OO-principles that are practically applicable for Javascript?

Javascript is a prototype-based object oriented language but can become class-based in a variety of ways, either by: Writing the functions to be used as classes by yourself Use a nifty class system in a framework (such as mootools…
29
votes
9 answers

What can go wrong if the Liskov substitution principle is violated?

I was following this highly voted question on possible violation of Liskov Substitution principle. I know what the Liskov Substitution principle is, but what is still not clear in my mind is what might go wrong if I as a developer do not think about…
18
votes
1 answer

Does Liskov Substitution Principle also apply to classes implementing an interface?

LSP states that classes should be substitutable for their base classes, meaning that derived and base classes should be semantically equivalent. But does LSP also apply to classes implementing an interface? In other words, if an interface method…
user1483278
  • 1,121
  • 1
  • 10
  • 14
17
votes
4 answers

Two contradicting definitions of Interface Segregation Principle – which one is correct?

When reading articles on ISP, there seem to be two contradicting definitions of ISP: According to first definition ( see 1, 2, 3), ISP states that classes implementing the interface shouldn't be forced to implement functionalities which they don't…
EdvRusj
  • 623
  • 6
  • 12
16
votes
3 answers

What is separation between policy and mechanism?

The Wikipedia article on separation of mechanism and policy says The separation of mechanism and policy is a design principle in computer science. It states that mechanisms (those parts of a system implementation that control the authorization of…
Tim
  • 5,405
  • 7
  • 48
  • 84
16
votes
6 answers

Loose Coupling in Object Oriented Design

I am trying to learn GRASP and I found this explained (here on page 3) about Low Coupling and I was very surprised when I found this: Consider the method addTrack for an Album class, two possible methods are: addTrack( Track t ) and addTrack( int…
Random42
  • 10,370
  • 10
  • 48
  • 65
15
votes
4 answers

How does the Law of Demeter apply to object-oriented systems regarding coupling and cohesion?

How does the Law of Demeter applied to object-oriented systems with coupling and cohesion? I was reading a book "Software development and professional practice" and came across the chapter about LoD, and was curious about how that principle is…
Jeremy
  • 161
  • 1
  • 5
15
votes
1 answer

How to verify the Liskov substitution principle in an inheritance hierarchy?

Inspired by this answer: Liskov Substitution Principle requires that Preconditions cannot be strengthened in a subtype. Postconditions cannot be weakened in a subtype. Invariants of the supertype must be preserved in a subtype. History…
14
votes
3 answers

Is there a conflict between YAGNI and SRP?

I my job, I am tasked with the responsibility of improving the code quality. To meet this responsibility I often pair program with developers and conduct sessions on design principles and design patterns. I was surprised by a developer who said…
Nachiappan Kumarappan
  • 1,404
  • 1
  • 9
  • 19
14
votes
2 answers

Dependency Inversion Principle: Understanding how both low level components and high level components depend on abstractions

I'm learning about the Dependency Inversion Principle. It states that: High level modules should not depend upon low-level modules. Both should depend upon abstractions. For a while I tried to understand what it means that both the high level…
Aviv Cohn
  • 21,190
  • 31
  • 118
  • 178
10
votes
2 answers

Difference between Single Source Of Truth and Single Responsibility Principle?

So I just found out about the term single source of truth while watching video series about programming code interviews. From what I understood it meant that the single source of truth is an encapsulation of any type of operation/logic that might be…
AvetisCodes
  • 1,544
  • 3
  • 14
  • 26
9
votes
5 answers

Are there any significant disadvantages to depending upon abstractions?

I was reading this wiki on the Stable Abstractions Principle (SAP). The SAP states that the more stable a package the more abstract it should be. This implies that if a package is less stable (more likely to change) then it should be more concrete.…
9
votes
5 answers

When to stop inheritance?

Once upon time ago I asked a question on Stack Overflow about inheritance. I have said I design chess engine in OOP fashion. So I inherit all my pieces from Piece abstract class but inheritance still goes. Let me show by code public abstract class…
8
votes
3 answers

"Extends is evil" vs. OCP?

As far as I have understood(?), the "Extends is evil" idea is in direct opposition to the Open Closed Principle? In here, the concept of OCP is presented as inherently using Extends: http://www.oodesign.com/open-close-principle.html While in for…
Juha Untinen
  • 983
  • 6
  • 14
8
votes
3 answers

Is it a basic principle, or highly desirable, to have class methods that return "$this" rather than a value?

I've really just begun to learn OOP. I started about a year ago and have written probably 15,000 lines of it. But I wrote it all with hardly any experience looking at other people's OOP. Most of my class functions return a value or make a change to…
Buttle Butkus
  • 476
  • 3
  • 16
1
2 3 4 5