Questions tagged [patterns-and-practices]

Design patterns (repeatable solutions to commonly occurring problems) and best practices in software engineering

Filter by
Sorted by
Tagged with
79
votes
2answers
12k 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 ...
6
votes
1answer
455 views

MVC: Display requested content via the View

I'm trying to learn how the MVC pattern works so have been playing around a bit. I just wrote this, which was making sense to me, until I wanted to display the array content which has been collect by ...
44
votes
11answers
7k views

Are error variables an anti-pattern or good design?

In order to handle several possible errors that shouldn't halt execution, I have an error variable that clients can check and use to throw exceptions. Is this an Anti-Pattern? Is there a better way to ...
21
votes
4answers
9k views

What is the name for the idiom using method chaining to build an object?

I frequently use a pattern where I using method chaining to setup an object, similar to a Builder or Prototype pattern, but not creating new objects with each method call, instead modifying the ...
29
votes
6answers
7k views

Should I place functions that are only used in one other function, within that function?

Specifically, I'm writing in JavaScript. Let's say my primary function is Function A. If Function A makes several calls to Function B, but Function B is not used anywhere else, then should I just ...
35
votes
6answers
37k views

What is the best way to initialize a child's reference to its parent?

I'm developing an object model that has lots of different parent/child classes. Each child object has a reference to its parent object. I can think of (and have tried) several ways to initialize the ...
3
votes
1answer
168 views

Should I follow patterns strictly?

I have a service which is an API client. It's goal is to instantiate a concrete client you tell it (different providers), implement it's methods (createRequest and doRequest) and forward their call ...
55
votes
4answers
33k views

When and for what purposes should the const keyword be used in C for variables?

While getting my code reviewed here the issue of using the const keyword came up. I understand that it is used for implementing read-only behaviour on variables. I am confused about what are the ...
3
votes
6answers
2k views

Best approach - convert multiple conditional if -else in a more handy design

I have a class that handles the state of a response, called StockResponse. The code has multiple ifs to handle each state of the stock. Most of the cases has a default behaviour, but some conditions ...
5
votes
1answer
417 views

How to make sure people call methods in the right order?

Situation I'm designing a database abstraction layer for sql (mysql, sqlite) and mongoDb. The goal is to give the user/developer a library which is able to create queries for different databases. ...
162
votes
11answers
26k views

What happened to the “Surgical Team” pattern from “The Mythical Man-Month”?

Years ago, when I read The Mythical Man-Month, I found lots of stuff which I already knew from other sources. However, there were also new things in there, despite the book being from 1975. One of ...
10
votes
5answers
6k views

Designing a robust architecture for multiple export types?

I'm looking for patterns or architectural guidance for an upcoming feature I'm designing. Basically, it's an export feature with multiple export targets, and I'm looking to find a way to make it ...
17
votes
4answers
10k views

What is “lambda” code?

I have recently heard people talk about code being "lambda". I have never heard of this phrase before. What does it mean?
20
votes
7answers
6k views

Advantages and disadvantages of using bit masks in database

Not so long ago I talked to my colleague and he was definitely against using bit masks because it is hard to understand all the values that are stored in the database. In my opinion it is not always a ...
7
votes
1answer
4k views

Repository Pattern and database queries

Having read others posts, it already seems to me that the concept "repository" and "database" do not go well hand in hand, as they are meant to be completely separate concepts.... but I'll ask the ...
2
votes
2answers
2k views

How Visual Studio could help to avoid duplicating code?

I work within a team of developers. Everyone is making their changes without carrying too much if the same thing is already implemented in the codebase. This leads to classes constantly growing and to ...
10
votes
2answers
7k views

Which is a better pattern (coding style) for validating arguments - hurdle (barrier) or fence? [duplicate]

I don't know if there are any accepted names for these patterns (or anti-patterns), but I like to call them what I call them here. Actually, that would be Question 1: What are accepted names for these ...
3
votes
2answers
330 views

Is there a name for this pattern?

A while loop can be written as follows in C# (and many other languages): int someValue; int someTerminatingValue; while ((someValue = GetSomeValue()) != someTerminatingValue) { // Do something ...
-4
votes
5answers
605 views

Why do programmers like to stick to “Thou shalt” / “Thou shalt not” rules that define whether a code is of good or bad quality? [closed]

I'm not sure how to correctly describe my problem... Ever since I started learning how to program, I recognized that many more experienced programmers have very strict (and, in the POV of a beginner, ...
8
votes
2answers
3k views

Is implementing an interface defined in a subpackage an anti-pattern?

Let's say I have the following: package me.my.pkg; public interface Something { /* ... couple of methods go here ... */ } and: package me.my; import me.my.pkg.Something; public class SomeClass ...
5
votes
5answers
2k views

I have generally read that having many (>4) arguments to a function/constructor is a bad practice. Is this still considered a bad practice? [closed]

I have generally read that having many (>4) arguments to a function/constructor is a bad practice. Is this still considered a bad practice? And is there a non-obvious reason? In something like a ...
5
votes
3answers
2k views

Is it right to skip unit testing and go straight writing integration tests if there's no point of testing the unit in isolation?

According to Martin Fowler's article, https://martinfowler.com/bliki/TestPyramid.html It is advisable to write more unit tests than integration tests. Does this mean ideally that every unit of work ...
5
votes
4answers
383 views

Is it normal to write all logs into a single file?

Our teamlead said that many files much worse than a single, despite of we are working on a big project. He argued that our customers could more easily send logs to us if there will be just a single ...
3
votes
3answers
3k views

CRUD operations in DDD

I'm designing an application with DDD. I'm moving from flat POCO objects to strong domain models, so my question is: Would I have to call my basic CRUD operations (located in my repository layer) ...
2
votes
2answers
217 views

Which pattern should I use for factory + wrapper

I have to program a generic client that uses diverse concrete clients (diverse APIs), all sharing the same interface. I have to log the response of the client. To accomplish this (logging in ...
2
votes
1answer
585 views

Design patterns to avoiding breaking the SRP while performing heavy data logging

A class that performs both computations and data logging* seems to have at least two responsibilities. Given a system for which the specifications require heavy data logging, what kind of design ...
1
vote
1answer
647 views

MVVM, is it better suited for web applications or GUIs?

I am currently deciding whether I should implement a new system with a web application as a front-end, or if I should instead produce an executable file using WPF. The pattern that I will use is MVVM,...
0
votes
1answer
171 views

Architecture for writing add-ins for closed-source software

currently I'm designing an add-in for the modelling tool Enterprise Architect. The general architecture is shown in the picture below. Basically every action where the add-in can react to is ...