Skip to main content

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

deriving , derived decorator classes. How? Does it sound like a good idea or are there more suitable ways?

I follow this example on decorator patterns to implement objects who's functionality can be dynamically be coupled together. Namely: class I: is the interface class, common to both "core" class and "...
nass's user avatar
  • 163
0 votes
2 answers
125 views

Statistics with SQL queries or in JavaScript

I have an excel like table with a should value and an is value for each day of a month: descrip. | | 01 | 02 | 03 | 04 | _______________________________________ column 1 | should | 60 | 0 | ...
devz's user avatar
  • 243
1 vote
1 answer
568 views

MVC, Services and DAO: Fundamental design choices, error handling and return values

Edit: There is no "right" or "wrong" answer here, I was merely trying to get people to share their dos and don'ts. Behind this rather vague topic I would like to address a few problems I've been ...
Tim's user avatar
  • 123
1 vote
1 answer
61 views

Factory injection into factory created object

public class Factory { public INode CreateNode(TypeEnum type) { switch(type) { case TypeEnum.Document: return new DocumentNode(this); case ...
HuorSwords's user avatar
0 votes
0 answers
100 views

Heuristics/rules for programming to an interface [duplicate]

I am struggling with applying the "programming to an interface" guideline because I can't seem to decide in which situations it is necessary and in which ones it's overkill (or even counter productive)...
carlossierra's user avatar
  • 1,405
6 votes
4 answers
569 views

Is it too verbose to always have 'modified' time stamps on all entities within a database?

The question can be summarized as: In a database (regardless of type), would it be considered a good practice to always include updated, created (and possibly deleted) properties, for all entities, ...
mausworks's user avatar
  • 778
26 votes
8 answers
11k 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 ...
Alex Ovechkin's user avatar
7 votes
1 answer
821 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 ...
MikeMason's user avatar
  • 319
6 votes
2 answers
2k views

Should repository have a method for every specific database operation?

When following the standard service and repository patterns, should your repository contain a specific method for every database operation or should you just use the general methods, e.g. update? Take ...
matthewrk's user avatar
  • 263
3 votes
2 answers
231 views

Could this be called a decorator pattern?

I want to add some extra methods closely related to Book without extending Book. So I found the decorator pattern. Most examples I have seen are eg. extending an abstract decorator class which ...
Thomas Andersen's user avatar
1 vote
2 answers
2k views

Design pattern for managing three different objects

I´m looking for the best way to solve following problem: I have three lists of different objects: AppleJuice, OrangeJuice & Juice. All Juice properties exists in AppleJuice & OrangeJuice ...
RCalaf's user avatar
  • 113
2 votes
2 answers
291 views

Should continous integration make the code deploy to an environment?

I got inspired by a similar question on the Stackoverflow.com and after reading what Martin Fowler has written (and Jez Humble, of course at http://continuousdelivery.com/), I still struggle to ...
Melioer's user avatar
  • 153
13 votes
5 answers
16k views

Should every class I write adhere to an interface?

I'm writing a game in Typescript, and decided going in that I was going to try to adhere to the idea of "interface based programming", where you write code based on an interface, instead of the ...
Carcigenicate's user avatar
2 votes
1 answer
305 views

Abstracting end-to-end test cases across multiple pages

I am using Protractor and Jasmine to create end-to-end tests for a webpage. To test this initial page, I have abstracted made some common utility functions to create about 20 test cases for this ...
LanceLafontaine's user avatar
1 vote
1 answer
1k views

Improving a try/catch

I'm a python programmer trying to get to grips with Java's inflexibility; I'm trying to parse a date from a string into a Calendar object private Calendar parsedDate ( String dateString ) throws ...
ChrisW's user avatar
  • 121
1 vote
1 answer
146 views

What is the minimal prototypical program to demonstrate the differences between the major programming paradigms?

Clearly the prototypical "Hello World" program does not suffice to demonstrate the difference between the major paradigms of programming. What would be the minimal program to show the differences ...
nilo de roock's user avatar
4 votes
2 answers
141 views

Should I use the same object for individual instances and collections?

One of the functions of an application I manage is to operate a fleet of vehicles. I have an object vehicle with which I can do tasks that are vehicle-related; getMileage(), setDriver(), etc. I also ...
boatingcow's user avatar
0 votes
1 answer
405 views

Is it a bad practice to use external files for storing SQL templates?

I am working on a report system which aggregate a lot of data from multiple sources (databases and internal APIs). Among other things I communicated with another departaments and told them I need some ...
Nikita U.'s user avatar
  • 173
8 votes
3 answers
3k views

Design: How to avoid breaking backward compatibility because of database changes

This is my scenario, I have this interface: public interface hitTheDataBase { public void insertMe(String [] values); public void modifyMe(String [] values); public DataTable selectMe(); }...
Broken_Window's user avatar
1 vote
4 answers
219 views

File-Directory Implementation: Does a a file have to own a reference to it's dir?

I am currently issuing a problem while forming the program-design, which is exact like a File-Directory relationship, and to ease it, I am using that as an example. I think it is usual, that a ...
user3698624's user avatar
0 votes
1 answer
97 views

How to design interface communication beween objects?

I'm stuck on a lightly philosophical question for me. I have three classes and I'm not sure how to make them related to each other. I have few competing approaches all of them standing on equal ground ...
edin-m's user avatar
  • 133
1 vote
1 answer
206 views

Is defining only one method against S in S.O.L.I.D

The first version of pseudo code I consider a code smell because of (I think) the Command Query Separation principle and/or the S in S.O.L.I.D. What I like to see is in the 2nd version. Should I keep ...
Clutch's user avatar
  • 123
2 votes
1 answer
2k views

Best practices for working with public_html folders and git

Currently, everything that is in the public_html folder automatically gets published live. The git repository is also inited in this folder (though this can change if it's necessary). What is a good ...
bluejay5's user avatar
1 vote
1 answer
1k views

Architecture of approval process

I want to design an approval process for my work flow but I wonder if there is an architecrural pattern or desing pattern for this solution. For example an engineer will create a work. And program ...
barteloma's user avatar
  • 319
1 vote
1 answer
345 views

Is it a common pattern in Python to have instance variables assigned in a constructor start with an underscore?

I recently started using UtilSnips, a Vim plugin allowing for a certain level of automation while coding by using template-like code snippets for common code fragments (class and function definitions, ...
Jules's user avatar
  • 361
3 votes
4 answers
3k views

Keeping a ratio column that's the division between two other columns

I'm about to build a SQL table where I want to store currency orders. That means that I need to store how much I paid for a certain quantity, and the ratio between both quantities. So for example: +--...
erictrigo's user avatar
  • 315
1 vote
0 answers
135 views

Relying on file hash for data synchronisation across mobile and server

Imagine a client-server app that lets user upload images/documents etc. to server and then lets users who have access, retrieve and view them later on their respective mobile devices. So the flow is ...
Mrchief's user avatar
  • 631
11 votes
8 answers
1k views

Designs and practices to guard against erroneous null entries from database

One part of my program fetches data from many tables and columns in my database for processing. Some of the columns might be null, but in the current processing context that is an error. This should "...
jhyot's user avatar
  • 429
19 votes
2 answers
18k views

Should a RESTful API be able to return files, or just a location

This has been puzzling me for a while. For example, we have a REST API that provides basic content to a system, consuming and producing JSON. At this endpoint it produces a URL to a picture and a ...
Crazy Dino's user avatar
3 votes
0 answers
81 views

Should my application call statsd directly or should I call statsd based off logs?

I'm planning on incrementing counters in statsd based of various events within my application. I have logging in place for these events. So, from my viewpoint I have two options: Update the ...
cynicaljoy's user avatar
3 votes
1 answer
995 views

Reusing array with static test data across test classes

I have a Map which takes in an a String key, and an array of custom objects as the value. the map usually contains two entries, and the arrays for both entries never change in terms of data; once they ...
jbailie1991's user avatar
18 votes
6 answers
11k views

Advantages of Strategy Pattern

Why is it beneficial to use the strategy pattern if you can just write your code in if/then cases? For example: I have a TaxPayer class, and one of its methods calculates the taxes using different ...
Armon Safai's user avatar
5 votes
3 answers
5k 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) ...
Franco's user avatar
  • 153
0 votes
1 answer
2k views

MVC Best practice mixing Partial View and JavaScript

I searched the internet and really can't find a good answer to this question. Imagine there is a View that contains a simple tab-element. Each tab-content is loaded dynamically (via ajax) when the ...
KingKerosin's user avatar
1 vote
2 answers
105 views

Explaining concepts [closed]

How can I explain a concept when I don't know its name or any formal reason for it? The reason I ask is this... A new programmer has entities with a property title in his system. He uses the title to ...
gerard's user avatar
  • 21
1 vote
0 answers
108 views

Algorithm for evaluating line breaks efficiently [closed]

Consider following problem : Given: String input with the length n Font(-metrics) - potentially slow in usage Bounds of an abstract Textview which shall contain the text in a specific manner: e.g ...
throws_exceptions_at_you's user avatar
2 votes
1 answer
118 views

Pattern for passing in a field as a parameter

I'm writing a Rails app which uses ActiveRecord ORM and a Postgres DB. I've got two attributes which are similar but are separate fields in the database. The assignment and saving of these is kinda ...
TheRealJimShady's user avatar
6 votes
1 answer
463 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. ...
aichingm's user avatar
  • 163
4 votes
4 answers
2k views

Where to store average value in db?

I have a restaurant review app which stores reviews in a db, MySql. There's 2 tables. 1 for Restaurant. Another for reviews. To increase the performance, I am considering to store the avg review of ...
Alexander's user avatar
  • 1,159
9 votes
4 answers
2k views

Is there a Haskell idiom for trying several functions and stop as soon as one succeeds?

In Haskell, I can use the type a -> Maybe b to model a function that either returns a value of type b, or returns nothing (it fails). If I have types a1, ..., a(n+1) and functions f1, ..., fn, ...
Giorgio's user avatar
  • 19.7k
3 votes
2 answers
360 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 ...
BanksySan's user avatar
  • 724
2 votes
2 answers
2k views

Joshua Bloch Enum Singleton and Third Party APIs

In the book Effective Java he give the best Singleton pattern implementation in his, that is implement by a Enum. I have doubt to how to implement this pattern with a third party API. I'm using an ...
alexpfx's user avatar
  • 303
3 votes
2 answers
488 views

Does it break SRP to have concerns of data handling and object mapping inside a single class, as part of the DataMapper pattern?

Summary I want to look into separating the concern of "creating a populated object from database", to use inside my application. DataMapper pattern seems to be doing just that for me. DataMapper ...
Dennis's user avatar
  • 8,247
13 votes
4 answers
4k views

Reducing boilerplate in class that implements interfaces through composition

I have a class: A that is a composite of a number of smaller classes, B, Cand D. B, C, and D implement interfaces IB, IC, and ID respectively. Since A supports all the functionality of B, C and D, A ...
Nick Udell's user avatar
  • 1,204
1 vote
1 answer
140 views

Name pattern for quickly find descendents with SQL (PATH column with [TopId]...[DirectAncestorId].[OwnId]) NO nested sets

I read a long time ago about a pattern/technique for easily querying for all "descendants" of a record (no need to use CONNECT TO, which is not standard and not available with JPA). I remembered the ...
SJuan76's user avatar
  • 2,522
3 votes
4 answers
1k views

Function wrappers with no args: bad practice?

My colleague likes to write classes containing methods looking like this: public function doTaskA() { return $this->doTask('A'); } public function doTaskB() { return $this->doTask('B'); ...
Benubird's user avatar
  • 218
14 votes
2 answers
9k views

Are the Repository Pattern and Active Record pattern compatible?

Currently I am developing a webapp where I have defined models implementing the Active Record pattern. Each model also is defined by an interface that specifies the Entity properties and makes it easy ...
marcanuy's user avatar
  • 253
2 votes
2 answers
282 views

Is it a good idea to install more libraries than you need? [closed]

I decided to try Anaconda, it seems that too many large companies are using it. I was amazed by the number of libraries included by default installing: python-2.7.9-2 ... installing: conda-3.10.0-...
Lynob's user avatar
  • 129
1 vote
1 answer
2k views

JSP in Javascript file or multiple AJAX requests

I've been thinking about how I want to load my data for some checkboxes in an AngularJS app. I'm generating multiple checkboxes based on 2 JSON objects that are currenty hard-coded in the a Javascript ...
Ahatius's user avatar
  • 111
4 votes
2 answers
496 views

Is it OK for an MVC view to request data from other sources than just the model?

I'm working in ASP.NET MVC, but this question is pretty much applicable to any MVC framework (and maybe even others). In a typical MVC application a request arrives at the controller, which then ...
Vilx-'s user avatar
  • 5,350

1
4
5
6 7 8