Skip to main content

Questions tagged [design-principles]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2 votes
3 answers
3k views

Pattern for costly precondition check before acting

Let's say I have a method DoTheThing() which requires the precondition-check CanTheThingBeDone() to return true. The latter method is time consuming as it accesses the database. I'm finding it hard ...
Nilzor's user avatar
  • 131
8 votes
5 answers
3k views

Martin Fowler's Refactoring book: switch statement is using other object's data, why is that bad ? A deeper explanation is sought for.

In the code sample below the Rental object is using Movie's fields to do a switch statement. Martin says : this is a bad idea but he does not give any deeper explanation as to why ? Of course, you ...
jhegedus's user avatar
  • 183
8 votes
3 answers
2k views

"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....
Juha Untinen's user avatar
1 vote
1 answer
262 views

Component design: getting cohesion right

I currently have a set of components named DataValues, ValueParsers, ValueFormatters and ValueValidators. The first one defines an abstract base class DataValue and contains a whole load of ...
Jeroen De Dauw's user avatar
16 votes
6 answers
5k views

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 ...
Random42's user avatar
  • 10.5k
17 votes
4 answers
6k views

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 ...
EdvRusj's user avatar
  • 623
2 votes
4 answers
238 views

Abstracting out a module or using the Module Singleton directly?

I am working on a module which is dependent on other module for some functionality. Now the dependent module provides a lot of functionality and I need only few of them, hence got the idea to create ...
Ravi Gupta's user avatar
8 votes
3 answers
483 views

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 ...
Buttle Butkus's user avatar
14 votes
4 answers
4k views

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

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, ...
Jeremy's user avatar
  • 151
3 votes
4 answers
162 views

Feature organization / authentication? [closed]

Let's say I have a product that has different features, or different feature access depending on things (i.e Premium User, Beta, Demo, Logged-in User, etc..). What's the best way to organize a system ...
Daniel's user avatar
  • 1,896
80 votes
2 answers
13k views

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 ...
Spoike's user avatar
  • 14.8k
18 votes
1 answer
2k views

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 ...
user1483278's user avatar
  • 1,141
29 votes
9 answers
11k views

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 ...
Geek's user avatar
  • 5,187
16 votes
1 answer
3k views

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 ...
Songo's user avatar
  • 6,598
9 votes
5 answers
1k views

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 ...
Freshblood's user avatar
  • 1,517
1 vote
3 answers
1k views

Recommended content for layers

As an expansion from my previous question about using separate projects for seperate layers - Good practice on Visual Studio Solutions I now wish to know if I am putting the right functionality in ...
JonWillis's user avatar
  • 429
2 votes
2 answers
256 views

Where does "isolating complexities" lie in the realm of design principles?

I was just curious, it's something I think most people are aware of as a technique: You have some abominable data that simply must be parsed and you can do nothing to simplify the algorithm for doing ...
Jimmy Hoffa's user avatar
  • 16.1k
4 votes
2 answers
206 views

Does the single responsibility principal promote flexibility?

Does the single responsibility principal promote flexibility? If not what are the other methods to make your classes more flexible? By flexibility I mean, a class is able to function correctly at any ...
Shaheer's user avatar
  • 889
4 votes
2 answers
283 views

Does KISS encourage tools and frameworks that expose complex leaky abstraction layers?

Tools and frameworks make complex tasks simple. This seems like something that would be supported by KISS(keep it simple stupid). Tools and frameworks also have the potential to introduce leaky layers ...
user avatar

1
2