BLoC State management ,Is it an Architecture pattern or Design pattern ?
To answer this question we must know first these keywords :State management,Architecture pattern,Design pattern.
and know the difference between the last two because most of people think they are the same, and this is extremely wrong!.
State management:
Simply it refers to the management of the state , a state here means data so It is a way to communicate and share data among the components. in another term it's the way to separate the logic from the UI.
Architecture pattern:
It is the way that we use to organize the components inside your code, to be easy to read to you and to other developers, Most of them have successfully solved various problems. In each pattern, the components are organized differently for solving a specific problem in software architectures such as MVC,MVVM,MVT...
Design pattern:
is a general solution to the commonly occurring problems in software designing, they are strategies, ideas not a particular implementation .By using design patterns, you can make your code more flexible, reusable, and maintainable.
And now what is BLoC and which one of these definitions is?
To use trigger a state change/ redraw flutter provides the setState function
@override
void setState() {
// TODO: implement setState
}
This function is perfect when you ara building a simple app but the problem arises when you are building complex apps where you might have multiple setState calls,in every call you will rebuild the entire screen just for one action ,your logic tightly coupled to the user interface(Widgets) and you might have to deal with unnecessary redraw of a widget can lead to performance issues. and here the BLoC came to solve this problem.
BLoC stands for Business Logic Components, it's a well known way to manage data within an application and helps to separate our logic from the user interface,It uses the concept of Streams, this means that when a stream of events is created, subscribers can listen in on the stream of events. The subscribers are notified of new data when it is emitted into the stream and return it in a state. Events & states , Events are what you sent to the bloc to be acted uopn and States are returned once the logic is executed .
coming back to our question, what is BLoC? Actully is a well known state management and it is an architectural pattern based on separate components (BLoC components). BLoC components contain only business logic, which can easily be shared between different app states, but It's not a design pattern itself because it's not a solution to a software problem, it's just built on the 'Observer' which is a design pattern so we can say that inside our app BLoC can be a design pattern.