This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Eyal Zaidman
Posted Feb 21 - Read on Facebook

Modules vs. Classes:
When and where is it advised to prefer modules over classes? Does a module serve as a static class?

Of course, when you want to crate more than one instance of a certain item - you'll use a class, but in what scenario would you prefer a module over a class?

For example: for implementing a status bar or a navigation bar (shared by different screens) - would you prefer a module or a class, and why?
Thanks in advance :)

6 Comments

Jordan Robert Dobson

Well they aren't really comparable... a module is just a location to store your code which could be a class or just a collection of functions and values.

Jordan Robert Dobson

I think I would use a class for a status bar if I was going to reuse it a lot and needed a simple way to interact with it.

It really all depends which is easier and makes sense for how you and your team builds prototypes

Eyal Zaidman

It is true that you would store a class in a module, but you could also store an "exported" layer in a module and use it (once or more) in other places. I wonder if there's a benefit for using this approach...
For instance - for implementing a login screen, which would be used in a FlowComponent, would you use a class or an exported layer (stored in a module)?

Rohan K

I think the point of a module is to package reusable code and make it easy to distribute. If the implementation of this code does not require one to modify it, go ahead and make it a module. However, I recently found out that if your module needs to access anything outside of itself without it being passed as a parameter, it might be a problem because of name spacing issues. Just sow ting you might want to keep in mind.

Steve Ruiz

If a thing actually creates a new layer, I use a class.

Mike Johnson

A module is only neccessary when you want to export some code across different framer files without retyping things. This is great for sharing your work with your team, other framers, or at framerco.de

If you are just making a nav bar to be shared among several screens in the same prototype then just use a class (if it even needs to be a class...) and use code-folds to tuck it out of the way.

Read the entire post on Facebook