Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [design-principles]

The tag has no usage guidance.

1
vote
1answer
97 views

How to write a class that uses other classes but needs the same functionality - should I just wrap around the methods?

I want to create a class ProcessHandler for Windows that pretty much uses the WINAPI. The class ProcessHandler should be able to scan memory, emulate keyboard and mouse, needs some DLLInjector, some ...
0
votes
3answers
220 views

Is it sometimes okay to intentionally violate the Dependency Inversion Principle?

I am doing some work to refactor a class. It currently a 'God class' and contains all different logic/operations solely in that class. One of my solutions is to extract all different parts of logic to ...
-2
votes
3answers
293 views

Are there any well known alternatives to the SOLID principles for OO programming? [closed]

I´m looking for some kind of better compilation of principles which takes the old basic concepts (DRY, KISS, etc...) and applies them to OOP related concepts like abstract clasess, interfaces etc... ...
1
vote
1answer
121 views

What are the potential dangers of using this kind of reflection cheat in Python?

In a program I'm working on, I need to do a substantial amount of real-time reflection in order to maintain a list of known "attributes" throughout the program structure (for use by a sort of "virtual ...
2
votes
1answer
155 views

Is it efficient and a normal practice to have one class with thousands of lines of code? [duplicate]

I am currently in a continuous software product development project on base of legacy Java code. The source code is very complicated, which is good and bad. But I am surprised to see that in the core ...
0
votes
2answers
117 views

Is there a coding style principle for making class usage consistent

I get to review code that often looks like this: class MyClass1 { constructor MyClass(initialiseParam1: Object) { // do something with initialiseParam1 } initialiseStep2() { ...
-1
votes
1answer
175 views

The Principle of Allowing One Way to accomplish a Task

What is the official name of the principle, in language design, where the language tries to offer one way of accomplishing a particular task (as opposed to have multiple ways of accomplishing the ...
1
vote
3answers
101 views

POLA, Constructor and Getters

As a followup to this question and one I asked a while ago, suppose if I had an Author class structured like this: class Book { private String title; private Set<Author> authorsSet; ...
1
vote
1answer
85 views

Abstract base class implementing an interface, providing a different one to its subclasses

Let's say I have an interface for the Command pattern with undo functionality: interface ICommand { void Execute(); void Undo(); } This comes with a contract. Basically the command can be in ...
1
vote
2answers
257 views

When to keep behaviour inside the domain object vs inside a service object?

So far I put functions into objects, if those functions work exclusively on the object's variables/state. Basically I'm following a non-anemic/rich domain model approach. However, it becomes more ...
4
votes
2answers
207 views

What algo/design pattern do i need to keep limited time series data constantly updated?

I'm a hobbyist coder; never worked professionally. I am not looking for anyone to write code for me, but I need to know how to approach this problem and, perhaps, ideas for further research. This ...
-3
votes
1answer
188 views

What are timeless and transferable design principles?

What are timeless software design principles? I've heard this term tossed around in the context of it being easy to learn a new language when you already know these transferable principles in another ...
1
vote
5answers
229 views

Dedicated method vs method with parameter

Suppose we've a permissionManager which tell us if user has some privileges to some action or not. We've quite a lot of them(dozen, maybe more). I see two ways to implement checks for a user, like a: ...
1
vote
0answers
128 views

SVOT and SSOT to Single Source of Version of the Truth (SSOVOT)

Having a Liquibase changelist (containing create table/column, alter table/column) I create a inmemory-database to create Hibernate entity-classes out of this inmemory-database. But the main task of ...
3
votes
1answer
524 views

Should the presentation layer use domain objects returned from the service layer?

As an example, if there is a controller that calls a CountryService class and the CountryService class uses a Countries class, should the CountryService return the CountriesClass to the controller? Or ...
1
vote
3answers
347 views

In interface-segregation principle (ISP) terms, what is meant by depending on unused methods?

The interface-segregation principle (ISP) states that no client should be forced to depend on methods it does not use. My question is: how exactly can a client depend on something that it does not ...
4
votes
1answer
359 views

Principle of least privilege vs Interface segregation principle

What is the difference of Principle of least privilege and Interface segregation principle? As much as I understand ISP is just the projection of PoLP on the OOD plain.
3
votes
3answers
331 views

How to “program to an interface”

I've read these questions: Understanding "programming to an interface" What is the point of an interface? Does it always make sense to "program to an interface" in Java? I don't ...
9
votes
5answers
617 views

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 ...
1
vote
0answers
80 views

clone(serialize) v. serialize(clone)

My objects serialize() method is dependent on a call to its clone() method, because of its options to get rid of unwanted data without changing the original instance: serialize: function(opt_filters) ...
3
votes
1answer
150 views

How do you keep up with 'requiring new methods in an interface' (Following LSP and adding new methods to interface seems to violate ISP)

I have a game that deals with opening and closing doors and the Door Engine deals with IDoor interface which has Open() and Close() contracts So far so good. the game is tested and works fine. Now a ...
4
votes
1answer
184 views

Where to initialize objects

I have an BallEntity class that is part of a game that uses a Entity Component System architecture. This class have 'components' that are like the attributes of that class. I create and initialize ...
2
votes
1answer
908 views

Is a class representing a JSON response a DTO, a domain object, or something else?

Consider a restful service in Spring MVC. I am wondering how to package my response classes, i.e. how to name the containing package. First I thought of them as being domain objects. But they are ...
7
votes
2answers
4k views

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 ...
0
votes
1answer
53 views

SOC and self-initializing configuration

Disclaimer: I'm using C# for code examples. But I guess they should be readable/understandable for everyone. If they are not: please leave a comment. Okay I have a Client-Server application. The ...
3
votes
4answers
522 views

YAGNI principle put to practice

I recently came across to this principle and so far it is clear the fact that doing things that you don't need at the moment is not feasible as they might not be used or might be changed. That being ...
1
vote
4answers
913 views

try/catch open/closed principle violation

I have three or more different custom exceptions that a class can throw and I need to use try/catch in order to discover which exception was thrown. In my point of view this piece of code violates ...
1
vote
1answer
389 views

Tell, Don't Ask and Immutability in a non-directional network

I'm working on a small project in which I'm attempting to practice relatively strict adherence to two ideas: Tell, don't ask (TDA) Immutability The main concept in this project is a Map (as in a ...
1
vote
2answers
179 views

Define fields only once

I'm looking for a method to describe fields in a structured way, so I am able to reuse it in various languages and levels of my application. For instance, if I'm developing an Android application ...
0
votes
1answer
267 views

Technical example of modeling a domain with OOD?

Considering favoring composition over inheritance and looking at various design patterns there are multiple approaches to modeling a domain. Say you have some Entities which are very similar in some ...
0
votes
2answers
95 views

putting methods in base class that doesnt make sense/belong there [closed]

I've been lately thinking over design principles and patterns and a question did strike me. Let us say, I want to design a racing game. I want to design the classes for a variety of cars. each car ...
8
votes
2answers
2k views

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 ...
3
votes
3answers
2k views

Implementing the Interface Segregation Principle

Does this IConvertible interface satisfy the Interface Segregation Principle (ie. the "I" in SOLID)? Here is the definition: public interface IConvertible { TypeCode GetTypeCode(); bool ...
2
votes
1answer
222 views

Single Responsibility Principle and higher levels of abstraction

Two common phrasings for the Single Responsibility Principle (SRP) are "each module should be responsible for a single feature or functionality in a system", and "each module should have only one ...
2
votes
3answers
2k 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 ...
7
votes
5answers
2k 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 ...
7
votes
3answers
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....
1
vote
1answer
225 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 ...
16
votes
6answers
4k 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 ...
13
votes
3answers
3k 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 ...
2
votes
4answers
196 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 ...
8
votes
3answers
453 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 ...
15
votes
4answers
3k 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, ...
3
votes
4answers
146 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 ...
79
votes
2answers
11k 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 ...
17
votes
1answer
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 ...
27
votes
9answers
6k 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 ...
14
votes
1answer
2k 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 ...
9
votes
5answers
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 ...
1
vote
3answers
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 ...