design-patterns

DAO and Data transfer object

删除回忆录丶 提交于 2021-02-19 08:15:07
问题 So in the Data transfer Object there should be only setters and getters.. However what about handling also inserting and deleting objects from the Data transfer Object? public class dto{ setters and getters... .. .. public void delete(){ CustomreDao.delete(this.ID); } } Would it be against the DAO pattern itself? Thanks in advance. 回答1: Ask yourself this: "how hard would it be to update the DAO's delete method?" If you have a lot of DTOs and suddenly need to change the DAO, then that's a lot

Is this precondition a violation of the Liskov Substitution Principle

二次信任 提交于 2021-02-19 01:16:13
问题 I have 3 classes, Account , CappedAccount , UserAccount , CappedAccount , and UserAccount both extend Account . Account contains the following: abstract class Account { ... /** * Attempts to add money to account. */ public void add(double amount) { balance += amount; } } CappedAccount overrides this behavior: public class CappedAccount extends Account { ... @Override public void add(double amount) { if (balance + amount > cap) { // New Precondition return; } balance += amount; } } UserAccount

Factory returning classes in TypeScript

拜拜、爱过 提交于 2021-02-18 23:47:57
问题 Wrote a library that, depending on the input data; creates classes and uses them inside a main class. To make the code more maintainable and readable, I've moved the class generation logic into a separate file that exports a factory function. Code was written in ES2015. Now I'm migrating to TypeScript. Here is a pseudo example: factory.ts export default function (foo:string) => { class A { value:string = foo + '-A'; } return { A }; }; Main.ts import factory from './factory'; export default

Factory returning classes in TypeScript

Deadly 提交于 2021-02-18 23:43:52
问题 Wrote a library that, depending on the input data; creates classes and uses them inside a main class. To make the code more maintainable and readable, I've moved the class generation logic into a separate file that exports a factory function. Code was written in ES2015. Now I'm migrating to TypeScript. Here is a pseudo example: factory.ts export default function (foo:string) => { class A { value:string = foo + '-A'; } return { A }; }; Main.ts import factory from './factory'; export default

1-dimensional Point-Process in R (spatstat)

拈花ヽ惹草 提交于 2021-02-18 19:33:32
问题 I have asked another question, which was closed as Too Broad. Now, I will try to specify. Again, I would like to simulate a 1-dimensional point process in R. So far, I've only been working on 2-dimensional simulations and would need a bit of help. My goal is a simulation like in the picture But, I only need the real line with the random points on it. I use spatstat and have already found out that I can generate random points on a 1-dim Line with: rpoisppOnLines(lambda, L, lmax = NULL, ...,

Job queue with job affinity

故事扮演 提交于 2021-02-18 10:08:31
问题 I am currently facing a problem for which I am pretty sure there is an official name, but I don't know what to search the web for. I hope that if I describe the problem and the solution I have in mind, somebody is able to tell me the name of the design pattern (if there is one that matches what I am going to describe). Basically, what I want to have is a job queue: I have multiple clients that create jobs (publishers), and a number of workers that process these jobs (consumers). Now I want to

When and how should I use enumeration classes rather than enums?

筅森魡賤 提交于 2021-02-18 05:22:30
问题 A developer at work recently started using a class pattern instead of enums in places where enums would usually fit. Instead, he uses something similar to that below: internal class Suit { public static readonly Suit Hearts = new Suit(); public static readonly Suit Diamonds = new Suit(); public static readonly Suit Spades = new Suit(); public static readonly Suit Clubs = new Suit(); public static readonly Suit Joker = new Suit(); private static Suit() { } public static bool IsMatch(Suit lhs,

When and how should I use enumeration classes rather than enums?

久未见 提交于 2021-02-18 05:22:22
问题 A developer at work recently started using a class pattern instead of enums in places where enums would usually fit. Instead, he uses something similar to that below: internal class Suit { public static readonly Suit Hearts = new Suit(); public static readonly Suit Diamonds = new Suit(); public static readonly Suit Spades = new Suit(); public static readonly Suit Clubs = new Suit(); public static readonly Suit Joker = new Suit(); private static Suit() { } public static bool IsMatch(Suit lhs,

Name of “notification-and-check” pubsub architecture?

余生颓废 提交于 2021-02-17 03:28:26
问题 Basic pubsub architecture question. At a high level, when designing pubsub, I sometimes face a choice between two architectures: Publish mutations or "new-state". Some DB state is mutated, and publishers notify of that change via pubsub. But they include enough information in the message so that the subscriber doesn't need to do a look-up on the DB. Imagine the subscriber has a cache of the DB. It could receive the mutations or new-state, and update its cache without doing a look-up.

Rxjs nested subscribe with multiple inner subscriptions

雨燕双飞 提交于 2021-02-17 01:53:20
问题 Original promise based code I'm trying to rewrite: parentPromise .then((parentResult) => { childPromise1 .then(child1Result => child1Handler(parentResult, child1Result)); childPromise2 .then(child1Result => child2Handler(parentResult, child2Result)); childPromise3 .then(child1Result => child3Handler(parentResult, child3Result)); }); I'm trying to figure a way how to avoid the nested subscriptions anti-pattern in the following scenario: parent$ .pipe(takeUntil(onDestroy$)) .subscribe(