I just ran in the way you did. In the same mxml it does show same object
id, but once I leave the screen and load it again I am getting a new object
id.

On Fri, Nov 14, 2014 at 4:07 AM, mark goldin <markzolo...@gmail.com> wrote:

> Yes, I understand what you are saying. I have several models. They all
> behave correctly and this one only creates a new instance every time.
> I have changed my code to look like other models:
> package
> {
> import com.adobe.cairngorm.model.IModelLocator;
> import flash.events.EventDispatcher;
>  [Bindable]
> public class ModelLocator extends EventDispatcher implements IModelLocator
> {
> private static var _instance:ModelLocator;
>
> public function ModelLocator(enforcer:SingletonEnforcer)
> {
> if (enforcer == null){
> throw new Error("You can have only one ModelLocator");
> }
> }
>  public static function getInstance():ModelLocator{
>  if (_instance == null){
> _instance = new ModelLocator(new SingletonEnforcer());
>  }
>  return _instance;
>  }
> }
> }
> class SingletonEnforcer{}
>
>
> On Fri, Nov 14, 2014 at 3:12 AM, Krüger, Olaf <okrue...@edscha.com> wrote:
>
>> >When I am debugging I see that _instance is always different object when
>> I get an instance of my singleton. Is that right?
>>
>> I don't know if this is helpful:
>> I've tested your singleton implementation by creating some instances of
>> 'ModelLocator'.
>> As expected it always returns the same instance of 'ModelLocator' with
>> the same "object id" (@9760161)'.
>> So if you have a different behaviour you should do some research to make
>> sure your singleton works as expected.
>>
>> <fx:Script>
>> <![CDATA[
>> private var modelLocator1:ModelLocator;
>> private var modelLocator2:ModelLocator;
>> private var modelLocator3:ModelLocator;
>> private var modelLocator4:ModelLocator;
>>
>> public function init():void{
>>         modelLocator1 = ModelLocator.getInstance();  // ModelLocator
>> (@9760161)
>>         modelLocator2 = ModelLocator.getInstance();  // ModelLocator
>> (@9760161)
>>         modelLocator3 = ModelLocator.getInstance();  // ModelLocator
>> (@9760161)
>>         modelLocator4 = ModelLocator.getInstance();  // ModelLocator
>> (@9760161)
>> }
>> ]]>
>> </fx:Script>
>>
>> Olaf
>>
>>
>> ________________________________
>>
>> Edscha Holding GmbH
>> Sitz der Gesellschaft: Remscheid
>> Registergericht: Wuppertal, HRB 22889
>> Geschäftsführung: Francisco J. Riberas Mera, Francisco López Peña, David
>> Vázquez Pascual, Torsten Greiner, Markus Kirchner, Hans-Peter Schulz und
>> Volker Weiss
>>
>> Vertretungsberechtigt sind nur Geschäftsführer und schriftlich
>> Bevollmächtigte.
>>
>> Solely Managing Directors or employees with a written proxy have got
>> power of representation.
>>
>> Der Inhalt dieser E-Mail einschließlich etwaiger beigefügter Dateien ist
>> vertraulich und nur für den Empfänger bestimmt. Sollten Sie nicht der
>> bestimmungsgemäße Empfänger sein, ist Ihnen jegliche Offenlegung,
>> Vervielfältigung, Weitergabe oder Nutzung des Inhalts untersagt. Bitte
>> informieren Sie in diesem Fall unverzüglich den Absender und löschen Sie
>> die E-Mail einschließlich etwaiger beigefügter Dateien von Ihrem System.
>> Vielen Dank.
>>
>> The contents of this e-mail including any attachments are confidential
>> and may be legally privileged. If you are not the intended recipient, any
>> disclosure, copying, distribution or use of its contents is strictly
>> prohibited, and you should please notify the sender immediately and then
>> delete this e-mail including any attachments from your system. Thank you.
>>
>
>

Reply via email to