Questions tagged [patterns-and-practices]

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

2
votes
3answers
1k views

What design pattern for a sequence of processors over the same list?

Imagine you have a list of Objects - like a list or array of objects representing users - and two processors: one adds/delete/modify some user under certain circumstances the other does the same ...
2
votes
1answer
226 views

Is it a best practice to use a mocking service for testing http requests?

Is it better to unit test using a mock library like 'nock' (nodejs) or to just test the server's http requests directly? Here is an example of my Express server test for testing if my server is up ...
2
votes
1answer
750 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 ...
2
votes
1answer
611 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 ...
2
votes
4answers
2k views

Design pattern for multiples APIs that do the same function

I retrieve some pieces of information from four forecasting APIs, I have three main methods that I will implement in each API's manager: history (only one of them provides this function) ...
2
votes
2answers
64 views

Relating to design and runtime - is it better to parallelize smaller sub-tasks or bundled tasks?

I'm programming a small web scraper in python which I want to speed up by parallelizing things. The scraper is crawling URLs whereby a single URL can represent an 'item' or an 'index'. An index in ...
2
votes
2answers
216 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
193 views

Combining Patterns: Fluent Builder and Null Object Pattern

I am currently wrestling around with some GUI code where I have a table whose rows correspond to some object, let's say a Person object. When the table initializes, it fills the table with the Person ...
2
votes
1answer
572 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 ...
2
votes
1answer
111 views

Traversing over two similar object structures using a pattern

Let's say I have an Object Structure like this that I import data into from a source: Reporting: Body: ReportingEntity: DocSpec Reports[]: ConstEntities[] DocSpec ...
2
votes
2answers
726 views

NoSQL/Mongo: Best practice for modeling 1:1 “relationships”?

I come from many years working with SQL Server. I am working now on a mobile game using GameSparks as the back-end which only supports NoSQL run on Mongo. I am creating a Computer Card Game and am ...
2
votes
2answers
271 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 ...
2
votes
1answer
174 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 ...
2
votes
1answer
126 views

Queue rescheduling naming convention (Command pattern)

For my project I'm creating a queueing mechanism based on the Command Pattern, which can execute one of a number of jobs. Jobs can add other jobs to the queue or can be added by a human. Most of the ...
2
votes
1answer
440 views

Unit-testing databases: test all possible permutations of read and write to table?

I am testing a resource management class that is interacting with a database or a file system, or a combination of both. I was wandering if it is the norm to test all possible permutations of read and ...
2
votes
1answer
884 views

prism and multiple screens

OK - I am studying Prism a little because of a "free weekend" offer on Pluralsight. As this is proving too complex for me, I went to the Prism book and looked at the forward, and this is what it said: ...
2
votes
0answers
71 views

Performance: Creating duplicate file

I have a Web server (Local) and File server(Remote). I need to create a duplicate of an xml file in the same location with different file name in the File server. The size of the file is random, but ...
2
votes
0answers
162 views

Proper pattern to use when sharing large amounts of code and a similar control flow?

So I'm currently building an application that allows a user to fill out paperwork digitally, and then that information is taken in by the server and a PDF is populated and returned to the user. The ...
2
votes
0answers
65 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 ...
2
votes
1answer
117 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 ...
2
votes
0answers
244 views

Callback pattern handling exceptions - Best practices in .NET 3.5

I am looking to implement the callback pattern with error handling such that error is caught and pass to the callback code with the response. Since I am using .NET 3.5, I cant use Task (TAP) pattern ...
2
votes
0answers
206 views

Pattern or solution for using classes with different interface the same way

What I would like to achieve is to use classes (now two, later more) with different interface the same way, so I would like avoid using decisions based on the interface on upper levels for instance, I ...
1
vote
4answers
372 views

Coworkers don't seem to care about best practices [closed]

I am a member of a 6 person team of software engineers within a 400 person department at a fairly well known company. We are responsible for the business applications our department uses, both third-...
1
vote
4answers
267 views

What should be the last entry in a switch/case statement?

When writing a switch statement that only ever has to deal with a known set of values (imagine an implicit enumeration), I find myself wondering what should be the last entry in the construct. I'm ...
1
vote
1answer
106 views

Should I make constant for values of three choices (trivalent/ternary)?

For two choices there is boolean. In my case, I have positive, negative, and neutral which are three choices and cannot be represented by boolean. I've see there's method Math.signum(x) in Java which ...
1
vote
1answer
611 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 ...
1
vote
1answer
144 views

use always get and set methods is a bad practique, is call directly an attribute class a bad practique in OOP?

I have a doubt about if there are some recommendations for call directly an attribute in a class I think that in OOP you always should call an attribute by the get method. For example: On set ...
1
vote
2answers
64 views

__init__ arguments differ from object attributes

Is the following class definition a good design? class Myclass: def __init__(self,num1,num2): self.complicated_tree = __class__.object_creator(num1,num2) @classmethod def ...
1
vote
2answers
91 views

Bridging application development practices and game development practices

I previously ran into an interesting practice called occlusion culling in game development. I am still researching to gain more understanding of how it works, since this is mostly discussed in game ...
1
vote
1answer
623 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,...
1
vote
1answer
145 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 ...
1
vote
3answers
482 views

How to signal that a method chain should not continue?

When doing method chaining, you have methods that return the object allowing you to continue the chain. However, you need to get values out of the object somehow. Usually I've added a method that ...
1
vote
1answer
2k views

Which practice is the best for database connection? (PHP, etc)

Leave a open database connection throughout the execution of the aplication, or for each time a operation will be executed a new connection will be created? Open throughout the execution: Open ...
1
vote
4answers
98 views

Passing Information to a method using primitives vs and object instance

I have trouble understanding if I should pass an argument to a method as a primitive value or as an already-obtained object. Consider this simple example interface Channel{ String getId(); ...
1
vote
1answer
156 views

Creating a web portal to access multiple databases (security and best practice?)

I am looking to create a website. There will be a portal, from which the user (and thier associated users) can create/access one or more databases. There will be many different databases in the ...
1
vote
2answers
189 views

What is the proper (or preferred way) to configure a static factory class?

First SE stack, I am working on a large chunk of old Java code and am finding tons of duplication and inconsistently configured/created objects because of different authors, skill levels, etc. I ...
1
vote
1answer
205 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 ...
1
vote
2answers
100 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 ...
1
vote
1answer
163 views

Obsessed with filling hashmaps instead of using else if cascades or switch statements [duplicate]

Whenever I feel like choosing from a list of implementations I always prefer to fill a map first and then call whatever I need based on a parameter, instead of using switch or else if statements. ...
1
vote
1answer
817 views

What is the “Find-Fix-Verify” pattern? [closed]

What is the "Find-Fix-Verify" pattern, as related to the process of doing editing/spellchecking/debugging, etc.? Where is this pattern best described? What are some advantages and disadvantages of ...
1
vote
5answers
262 views

Is it a bad practice to create a global factory?

I am studing the importance of the design pattern and I am not able to understand if could be a bad behavior to create a global static factory class (maybe using singleton?) I put an example hoping ...
1
vote
2answers
304 views

DDD: Is there a place for “find or create” in the business logic

Some user actions quite naturally lead to find-or-create situations. For example, user logs into a system by alternative method and find-or-create is called give email. Or, another example, User is ...
1
vote
2answers
136 views

Bundling Model and Services in MVC pattern?

These days, all I hear is how MVC should contain additional layer called services, turning it into SMVC. But to me, it seems like too much of a decoupling and instead want to engineer my app something ...
1
vote
2answers
380 views

Bridge pattern with inheritance (applying bridge pattern to subclass)

All of the examples of bridge pattern show only one level of inheritance, but I would want to apply it to a subclass of the base class too. The RefinedClass adds functionality to the BaseClass. In ...
1
vote
1answer
197 views

Hanabi card game: Correctly structuring the deck code

I'm trying to improve my understanding and ability to write code that uses recommended principles and practices, such as the SOLID principles. To do this, I am implementing the fireworks card game ...
1
vote
4answers
189 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 ...
1
vote
2answers
1k 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 ...
1
vote
1answer
4k views

Design Pattern for Cron/Schedule in MongoDB

I am looking for a good pattern to handle cron-type data in a MongoDB collection (or collections). I have been peeking at the O'Reilly book MongoDB Applied Design Patterns and poking around the ...
1
vote
3answers
1k views

Writing an application prototype - best practices?

For a project I am working I want to implement a small prototype to try things out, demonstrate some functionality to the client and learn some frameworks used in the project. Do you have any ...
1
vote
1answer
778 views

How to control optional dependencies of a header-only library in `CMake`?

I am developing my own header-only library that I want to use as a framework in other software. I am using CMake for setting up demo targets, tests, and so on. However, I am unsure how to deal with ...