17

While learning about Redux, the God-object pattern(or anti-pattern) came to my mind- both have a single big object holding all the app data and methods to manipulate them. But Redux has put some constraints like making the Object immutable and events pure functions maintaining strict signature.

So the question came, is Redux using a sanitized version of God object? Or, there is something to do with Javascript not being classical strongly typed OOP?

gnat
  • 20,543
  • 29
  • 115
  • 306
Gulshan
  • 9,532

3 Answers3

6

What is a God object? From Wikipedia:

Most of [a God object containing] program's overall functionality is coded into a single "all-knowing" object, which maintains most of the information about the entire program, and also provides most of the methods for manipulating this data. Because this object holds so much data and requires so many methods, its role in the program becomes God-like (all-knowing and all-encompassing).

The Redux store only contains one data object and only requires 2 or 3 methods. In this respect it's hard to imagine thinking of it as a God object. It is decidedly not "all knowing."

Now if your reducer is not broken up at all, if all of the logic is in one function, then that might qualify but it's a simple matter to break up the reducer into a bunch of smaller pieces to avoid the situation.

Daniel T.
  • 3,053
2

IMO, The above question should not arise. Functional programming concepts are not comparable to concepts in OOPS, they are just different ways of solving same problem. enter image description here

Anand
  • 181
0

The first page makes it abundantly clear that Redux solves a problem that is specific to single page web apps:

As the requirements for JavaScript single-page applications have become increasingly complicated, our code must manage more state than ever before. (from Redux - Motivation)

My own translation is - web apps and the frameworks for creating web apps are messy and as they're running in a browser they are faced with a unique set of problems that just don't arise outside of web apps.

Don't get me wrong - I am not saying web apps are bad, or that the frameworks are bad. It's just that web pages and the entire paradigm about it undeniably never was designed with applications in mind. Some web apps work remarkably well - I love Google Docs for example, it's better than the native app equivalents.

But Redux is just a tool to manage the problems that arise when you have to deal with the limitations and issues that come from creating web apps that run in a browser.

For an iOS app, or a native app of any kind, it doesn't make sense. Object model handles async changes and user interaction with ease. You'll always know what's going on. Rendering different states is not an issue and is automated with MVC and update events.

You're never faced with a situation like web apps are.

** If your architecture is bad, then well, nothing can save you, not even Redux ;)

n13
  • 161