nic-dgl104-winter-2024 / pattern-library

A multi-language library containing implementations of common software design and architecture patterns
4 stars 37 forks source link

Add code for issue in react native #75

Closed BALJITSINGH23 closed 7 months ago

BALJITSINGH23 commented 8 months ago

HI @ash-teach give me feedback on this code i used function here

swathysukumaran commented 7 months ago

Hi, I am unfamiliar with react native. could you please explain what is the purpose of MySingleton.instance;? I think a comment with that info would help react native dummies like me.

ash-teach commented 7 months ago

Hi @BALJITSINGH23 this is a near duplicate of pull request #54, which @Anjitha-94 is assigned to. There are some issues relating to #54 that should be addressed: Perhaps you can perform a code review of #54 and provide some suggestion on how to improve? Or you and @Anjitha-94 could work together, if possible?

BALJITSINGH23 commented 7 months ago

YES, i used function to solve.

BALJITSINGH23 commented 7 months ago

@swathysukumaran In React Native, MySingleton.instance is being utilized to implement a Singleton pattern. A Singleton is a design pattern that restricts the instantiation of a class to one "single" instance. In this code snippet, MySingleton.instance serves as a way to keep track of whether an instance of MySingleton has already been created.

BALJITSINGH23 commented 7 months ago

@AditiVatish In JavaScript, especially in environments like React Native, modules are used to organize code into reusable components. When you export default a class, function, or any other value, you're essentially saying that this is the main thing being exported from this module. If you don't intend to use MySingleton in other parts of your application or if it's intended to be a standalone module, you might not need to export it. However, if you plan to reuse MySingleton across different parts of your application, exporting it allows other modules to import and utilize it.