While we develop Embedded Software C++11, when does it make sense to use a Visitor-Pattern?
An example scenario would help in understanding this completely.
While we develop Embedded Software C++11, when does it make sense to use a Visitor-Pattern?
An example scenario would help in understanding this completely.
I want to separate routes from controller.
I tried this approach:
routes/index.js
var express = require('express');
var router = express.Router();
var wordMapperController = require('../controller/wordmapper');
router.get('/', wordMapperController());
module.exports = router;
conroller/wordmapper.js
var __construct = function(req, res, next) {
res.render('index', { title: 'Word Mapping for Sanskrit-Indonesian in BG' });
next();
}
module.exports = __construct;
When I start the res is undefined, and prevent the app to be launched. How does I handle this? How is it app.use and handle router middleware being passed?
While searching for ways to get an instance of a singleton class i found many different approaches (some simple, some convoluted) but when messing around i found a way to do it which i didn't find anywhere else.
So what i basically do is:
public class Foo
{
public static Foo Invoker;
public Foo()
{
Invoker = this;
}
public void Method1()
{
//.....
}
}
And then from another class
public class Foo2
{
public Foo2()
{
//.....
}
public void Main()
{
var foo = Foo.Invoker;
//or
Foo.Invoker.Method1();
}
}
My app is single threaded so i don't care about thread safety (should i?) , so are there any other problems that this approach could cause that i am missing?
In our application we use microservices architecture. One of the microservice is allocation microservice. This allocation microservice functionality is to assign 100 different records to the user who has logged in our application, from Postgres DB which has a total records of 1 million in one of the table.
Currently we are using spring boot and we are handling it using Optimistic locking mechanism. For even, When around than 100 concurrent users are using the application, the performance of the application is drastically slow, and the allocation microservice takes about more than 2 minutes to allocate the data to users. Once the data is allocated, we are storing the data in redis.
(Its a DB update, we change the status from "assigned" to "allocated" and also update the "assignedTo" field to the particular user. The use case is, no two same records should be allocated to the same user, to avoid this we are using "Optimistic lock" and the performance of the System is very slow in this case. Any other solutions to improve the performance ?)
Any other solution to improve the performance apart from Optimistic locking?
I have my small project where I wrapped object of one class with another class. Decorated class implements one interface but Decorator class does not implement it. I am curious whether it is still decorator pattern or some other pattern and "Decorator" class should be called Wrapper instead of Decorator in my project.
I have checked iluwatar github repository (https://github.com/iluwatar/java-design-patterns/tree/master/decorator/src/main/java/com/iluwatar/decorator) and tutorialspoint (https://www.tutorialspoint.com/design_pattern/decorator_pattern). For example in iluwatar there is: Decorator:
public class ClubbedTroll implements Troll
Decorated:
public class SimpleTroll implements Troll
In both cases (iluwatar and tutorialspoint) there is common interface implementation in decorator and decorated class. Does it mean it is mandatory to call it decorator design pattern?
Currently, we are doing different querying (MongoDb) based upon which data we required then creating a model for that particular report and creating a list or map of that model class then creating a workbook excel object. Now querying(fine-tuned query) is giving huge data that huge data need to simplify then putting into a model than creating excel workbook then sending to UI/Mail.
Instead of MVC any other design pattern which we can use for different reports. we have a different type of reports and some report columns are configurable based upon that configurable column and requirement we have to do sorting before putting into workbook object.
MongoDB {Query- to get the data.} simplify the data as per the required columns { which column is required from different tables/collections put into report model } { sorting based upon giving data }
{ creating a workbook object and start put data into that }
it's working but taking to much time I want to refactor the whole code using the design pattern.
Is it possible to simplify this code? I am transforming data from a list of values into the same Object. In each method the property being summed changes.
Properties follow the same naming convention every time (paios or pa) followed by (InUse or SuportInUse). I know in JavaScript I could generate the strings and eval the string, but as far as I know there is nothing similar in C#.
public class CompanyLicValues
{
public int Paios;
public int Papc;
public int Paplus;
public int Eis;
public int Pd;
public int Dropoff;
public CompanyLicValues SumInUse(List<vwCompany> companies)
{
Paios = companies.Sum(x => x.paiosInUse); //<<<The property being summed changes
Papc = companies.Sum(x => x.papcInUse); //<<<The property being summed changes
....
return this;
}
public CompanyLicValues SumSupportUsed(List<vwCompany> companies)
{
Paios = companies.Sum(x => x.paiosSupportInUse); //<<<The property being summed changes
Papc = companies.Sum(x => x.papcSupportInUse); //<<<The property being summed changes
...
return this;
}
}