samedi 27 mai 2017

How to apply OO design patterns in a NodeJS project?

i'm doing a project in NodeJS about finantial control that uses a model for accounts (Class Accounts) which have some "private" attributes (_id, _name, _parent, _balance and _isDeleted) and some methods (get attributes..., set attributes...).

All created accounts (objects) are converted into a JSON and stored into a file (custom database), except their methods (only the attributes are passed to the JSON).

When i load the database file, i get the JSON containing all accounts and their attributes, and need to show them into a view page, using EJS engine.

But after converting into JSON and loading them they doesn't have their methods to get their "private" attributes anymore, and i couldn't think any way to get those info, except by using directly the attribute reference (like _id, _name ...).

How can i get those attributes according to OO design patterns, avoiding to make external references to private attributes of a class?

Thanks!

Aucun commentaire:

Enregistrer un commentaire