samedi 1 septembre 2018

NodeJS Worker Pattern with external plugins

I am writing a NodeJS service that aggregates data from many different sources. The sources it pulls data from are in the form of Plugin classes, and each Plugin has one or more DataSource objects that handle data fetching and processing.

I am trying to implement the Worker Pattern, where the service will load each plugin and its respective DataSource classes and spawn a pool of workers.

Implementing this would be trivial if all of the plugins did the same exact thing, but it becomes more difficult when considering the post-processing operations that each of the individual plugins define.

Consider the following pseudocode for an example DataSource:

class DataSource {
  GetWork() {
    LookForNewData()
    LookForExistingUnprocessedData()
  }

  DoWork( work ) {
    DownloadNewData()
    ProcessNewData()
  }
}

It would be one thing if the DataSource simply downloaded data and saved it directly to a database, but since each DataSource processes the downloaded data differently, the worker needs to be able to have the class and its processing functions readily available.

I have considered a few solutions, but none of them seem very appealing:

  • Have a worker process for each DataSource
    • This could ultimately result in hundreds of child processes
  • Pass the work and the location of the DataSource.js file to the worker, have it include and cache the instance
    • This is the most promising solution, but seems very fragile and unnecesary

Are there any design patterns or existing solutions to a problem like this that can offer a cleaner implementation of what I am trying to do?

What are some resources to learn advance haskell and good practices and design patterns in haskell

I Have been using haskell for past 4 months now and i am quite comfortable with the language but one thing that keep bugging me is the thought that "is this the haskellish way of doing things ??", now i want to learn more advanced topics in haskell and at the same time i want to learn more about haskell design patterns and good practices, so please suggest the resources for that blogs, books etc anything.

approach while creating reusable table in angular 6

in angular, i have xyz component, which have child component table component and table component have table row component.

greenProduction=[{firstName:'test',surname:'test1',phoneNumber:'1234567889'}]
yellowProduction=[{firstName:'test',surname:'test1',phoneNumber:'1234567889',gender:'M',city:'Hyderabad'}]

yellowProduction have 2 extra properties.

xyz.component looks like

<div>
<app-table source="greenProduction">
<div>
<div>
<app-table source="yellowProduction">
<div>

table.component.html looks like with *ngFor

<div >
<app-table-row  [item]="item" (editItem)="editItem($event)" (deleteItem)="deleteItem($event)"></app-table-row>
</div>

table-row.component.html looks like with

<div>
 
 

<button (click)="editgreenItem(item)"> edit</button>
<button (click)="deletegreenItem(item)" > remove  </button>
</div>

Question 1 : should I able to use same table for both source ? greenProduction and yellowProduction ?

Question 2 : if #1 question answer is yes, how can I add 2 extra properties based on yellow product source in table-row component?

Question 3: how can I handle edit and delete event for both source? what angular patterns people using ?

This event @output emitted to app-table-row.ts = > app-table.component.ts have below events :

deletegreenItem($event){
  // how can we decide green or yellow production edit events call ? – I do not want to use if condition.
}

editgreenItem($event){
  // how can we decide green or yellow production delete events? – I do not want to use if condition.
}

For example :

When I clicked on delete on 1st table – I wanted to show “are you sure want to delete green production.” and go for it’s service call. When I clicked on delete on 2st table – I wanted to show “are you sure want to delete yellow production.” and go for it’s service call.

Question 4 : I am looking for generic solution, how can we use table component with row component N numbers of times in my app , means future if I have “red component” I do not like to add any if condition anywhere.

or any suggestion welcome :)

Thanks in advance.

which design pattern use reactive programming

I need to know what are difference between below design pattern and which one is use reactive programming

Decorator

Observer

Facade

Proper way to create presenter in MVP

I was looking at the google samples for MVP and I saw this as the last statement in onCreate of the activity:

new TaskDetailPresenter(  
                taskId,  
                Injection.provideTasksRepository(getApplicationContext()),  
taskDetailFragment);

This code seems weird to me.
It instantiates an object that is local and not assigned anywhere and in it associates the fragment with the presenter.

Is this really how it is supposed to be done? Because it seems not a good practice to me

vendredi 31 août 2018

Which design pattern to serialise object Builder vs Visitor ?

I am trying to learn OOPS by examples. So I try to implement a object serialiser.The object is same but it can be serialised to either XML, JSON etc. I see two types of suggestions out there.

In this blog, they say we can use visitor/double dispatch to serialise objects.

http://codebetter.com/jeremymiller/2007/10/31/be-not-afraid-of-the-visitor-the-big-bad-composite-or-their-little-friend-double-dispatch/

But, by definition we are building a serialised object from a complex object, so it make sense to create a XMLBuilder and JSONBuilder.

Now, which is the right way to do it ?

Inject Configuration into Python Applications

I'm looking for patterns for parameterizing Python applications.

Approaches I can think of are:

  1. pass configuration objects or parameters down deep call hierarchies
  2. have a singleton configuration object (eg. a package that's initialized at application startup)
  3. register configurable parts of the application upon load (import), then call them once the configuration is read
  4. every configurable component parses its own configuration

They all feel weird in one way or another.

The question is: is there a better alternative, what are the pros and cons of these methods, is there a best practice and are there standard implementations that I'm not aware of?