enter image description hereI need to make this design in flutter , this a sample chat box in chat screen
I was make it but this slidible is not work wenter image description hereith me
enter image description hereI need to make this design in flutter , this a sample chat box in chat screen
I was make it but this slidible is not work wenter image description hereith me
I want to understand what is the main difference in these two diagrams when it comes to the Model-View-Controller pattern. If there is a difference, how should I choose to construct my program? What conditions should make me choose the first design (or the second)?
But I am not even entirely sure if they are different, they could be meaning the same thing at the end of the day. I hope someone can explain, thank you
Everything is in the title but for the sake of it:
The company I work for has a really big Ruby On Rails app. After years of development we realized it lacked of logging. Production incidents were sometimes really hard to track and consequently to resolve.
So there was that issue in our backlog to improve the whole logging system.
I started added custom loggers for classes here and there, when really required but it seemed kind of dumb to copy / paste that piece of logic everywhere.
So i wondered: How to properly create dedicated loggers for desired Ruby on Rails classes, in a nice, compact and generic way ?
I'm catching up on "modern" C++ and a lot of what I've read says that I should prioritise value types, as they often lead to simpler code. I'm exploring how this works with a simple interpretation of the Factory Method design pattern, using a free function to avoid client code having to specify the concrete type explicitly.
I have a polymorphic type implemented by public inheritance, and I wish to store an instance of this type in another object. Thus I must store a pointer to get polymorphic behaviour on this type. This already makes it difficult to deal only with values, but I can hide this inside the Contains class if I implement clone().
class Base {
public:
virtual std::unique_ptr<Base> clone() = 0;
virtual void foo() = 0;
};
class Derived : public Base {
public:
std::unique_ptr<Base> clone() override {
return std::make_unique<Derived>(*this);
}
void foo() override { /* do something polymorphic */ }
};
class Contains {
public:
void store(Base & base) {
s_ = base.clone();
}
void do_foo() {
s_->foo(); // call polymorphic function
}
private:
std::unique_ptr<Base> s_;
};
// Factory function
Derived derived() { return Derived {}; }
https://godbolt.org/z/P1Eddcbsj
In the above code, Contains::store() makes a copy of the value passed by reference, and takes ownership via a unique_ptr. In this case, the factory function creates a value, and copies are made (and owned) by instances of Contains. The user of the factory function does not need to worry about ownership (unique or shared?) or passing unique_ptrs to Derived around.
But there's another way to do it, where the factory function returns a unique_ptr<Base> instead of a value:
class Base { ... } // as above
class Derived { ... } // as above
class Contains {
public:
void store(std::unique_ptr<Base> & base) {
s_ = base->clone();
}
// ...
private:
std::unique_ptr<Base> s_;
};
std::unique_ptr<Base> derived() { return std::make_unique<Derived>(); }
https://godbolt.org/z/hj4ed4v31
The store function has to take a reference otherwise the caller is unable to pass the pointer by value (because passing a smart pointer by value doesn't activate polymorphism):
int main() {
auto d = derived();
Contains c {};
c.store(d);
c.do_foo();
}
I note that the factory function should return unique_ptr and not shared_ptr, because ownership can always be "upgraded" to a shared_ptr, but it can't go in the reverse direction, so the unique_ptr is the more general type of smart pointer to return.
Questions:
In this situation, heap allocation of the polymorphic object is generally unavoidable, as the handle to the object must be a pointer (or reference) to activate polymorphic behaviour. However, this can be encapsulated, thus hidden from the client code. Or the smart pointer can be used to pass around the created object.
Given this, which of these two approaches to the simplified Factory Method pattern is the most idiomatic in modern C++, and will lead to the least problems down the track as the code grows?
Is there another approach I haven't considered that is superior, or worthy of serious consideration?
There some jobs in an electronic-machine system, the micro-controller need to process these in sequence, and each job will taken some time (eg: motor run to some position) jobs: A->B->C->D
Before, we use MCU like AVR, which only have one thread, we manage these jobs in a state-machine, the code pattern as follows:
void flow()
{
if (checkCondition())
{
return;
}
switch(state)
{
case A:
actionA();
state = B;
break;
case B:
actionB();
state = C;
break;
...
}
}
In this pattern, the function flow() is called in a loop, once the state changed, some waiting condition flags will be set, then these flags will be checked in the checkCondition(). Disadvantage of this pattern: when there are too many jobs, the code will be splited into pieces by the "case". Now, we plan to reconstitute the software based on STM32+RTOS, and we think the previous pattern might not be the best practice in multi-thread.
What's the best practice to manage these jobs in multi-thread system?
I have a method method update(Student std, Boolean isupdateRequired) On the basis of isupdateRequired flag i am updating the value of Student Object.
Now it's simple and i am not marking any columns value as true/false by using isupdateRequired.
Now my questions is that for above mentioned case is Enum is better option instead of Boolean? If yes why to use Enum.
I'm developing a code where I need to consume a json message from a queue and mapping to a java class to verify some values field and decide what flow/process i have to do.
if (car.getName.equals("Audi") && car.getDoors >= 2){
//do some proccess in other class
}
if (car.getName.equals("Opel") && car.getDoors < 2){
//do some proccess in other class
}
if (car.getEnginePower > 1500){
//do some proccess in other class
}
The problem is obvious, i need always to add a new if statement when a new rule in business logic is added.
What is the best behaviour design pattern to avoid this if/else strategy to try not Open–Closed principle.