design-patterns

Rxjs nested subscribe with multiple inner subscriptions

核能气质少年 提交于 2021-02-17 01:50:04
问题 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(

Rxjs nested subscribe with multiple inner subscriptions

拥有回忆 提交于 2021-02-17 01:49:12
问题 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(

Domain validation using the notification pattern

十年热恋 提交于 2021-02-16 13:57:26
问题 Historically I have performed validation of my objects within their constructors and thrown an exception when validation fails. For example: class Name { const MIN_LENGTH = 1; const MAX_LENGTH = 120; private $value; public function __construct(string $name) { if (!$this->isValidNameLength($name)) { throw new InvalidArgumentException( sprintf('The name must be between %d and %d characters long', self::MIN_LENGTH, self::MAX_LENGTH) ); } $this->value = $name; } public function changeName(string

Domain validation using the notification pattern

荒凉一梦 提交于 2021-02-16 13:57:06
问题 Historically I have performed validation of my objects within their constructors and thrown an exception when validation fails. For example: class Name { const MIN_LENGTH = 1; const MAX_LENGTH = 120; private $value; public function __construct(string $name) { if (!$this->isValidNameLength($name)) { throw new InvalidArgumentException( sprintf('The name must be between %d and %d characters long', self::MIN_LENGTH, self::MAX_LENGTH) ); } $this->value = $name; } public function changeName(string

Is It a Good Idea to Make Singleton's getInstance() Method Asynchronous by Making It Returns an Observable<Singleton>?

随声附和 提交于 2021-02-11 15:25:12
问题 I have a singleton that takes a few seconds to instantiate. It makes the UI freezes. So I'm planning to make the getInstance() method asynchronous. Is writing the following code a common practice? /* * The singleton class */ public class Singleton { private static volatile Singleton instance; public static Observable<Singleton> getInstance(Context context) { return Observable.fromCallable(() -> { synchronized (Singleton.class) { if (instance == null) instance = new Singleton(context

Better approach to call external API in apache beam

这一生的挚爱 提交于 2021-02-11 14:39:47
问题 I have 2 approaches to initialize the HttpClient in order to make an API call from a ParDo in Apache Beam. Approach 1: Initialise the HttpClient object in the StartBundle and close the HttpClient in FinishBundle . The code is as follows: public class ProcessNewIncomingRequest extends DoFn<String, KV<String, String>> { @StartBundle public void startBundle() { HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create(<Custom_URL>)) .build();

Unit of Work and EF

你离开我真会死。 提交于 2021-02-11 08:22:49
问题 I'm making an interface following the Unit of Work pattern. My interface looks like this: public interface IDataContext : IDisposable { void SaveChanges(); TSource Create<TSource>(TSource toCreate) where TSource : class; TSource Update<TSource>(TSource toUpdate) where TSource : class; bool Delete<TSource>(TSource toDelete) where TSource : class; IQueryable<TSource> Query<TSource>(); } So far so good. Now I implement it in my Data Layer, which uses EF4 as data provider. I came up with this

Unit of Work and EF

混江龙づ霸主 提交于 2021-02-11 08:22:15
问题 I'm making an interface following the Unit of Work pattern. My interface looks like this: public interface IDataContext : IDisposable { void SaveChanges(); TSource Create<TSource>(TSource toCreate) where TSource : class; TSource Update<TSource>(TSource toUpdate) where TSource : class; bool Delete<TSource>(TSource toDelete) where TSource : class; IQueryable<TSource> Query<TSource>(); } So far so good. Now I implement it in my Data Layer, which uses EF4 as data provider. I came up with this

Unit of Work and EF

淺唱寂寞╮ 提交于 2021-02-11 08:21:47
问题 I'm making an interface following the Unit of Work pattern. My interface looks like this: public interface IDataContext : IDisposable { void SaveChanges(); TSource Create<TSource>(TSource toCreate) where TSource : class; TSource Update<TSource>(TSource toUpdate) where TSource : class; bool Delete<TSource>(TSource toDelete) where TSource : class; IQueryable<TSource> Query<TSource>(); } So far so good. Now I implement it in my Data Layer, which uses EF4 as data provider. I came up with this

How to return a List inside this bounded generic method?

大兔子大兔子 提交于 2021-02-10 20:14:21
问题 I have class Response public class Response<T extends ResponseData> { private final T data; //other fields, getters, setters ... } and the empty interface ResponseData: public interface ResponseData { } It takes any object as data but this object must implement the "empty" interface which I created just to force all classes returned inside "data" element be of same super type Now the problem is that I need to return a List inside the data element, but: I don't find it clean to create a