b'\n_START_ARTICLE_\nLusta inicializ\xc3\xa1ci\xc3\xb3 programtervez\xc3\xa9si minta\n_START_PARAGRAPH_\nA sz\xc3\xa1m\xc3\xadt\xc3\xb3g\xc3\xa9pes programoz\xc3\xa1sban, a lusta inicializ\xc3\xa1ci\xc3\xb3 programtervez\xc3\xa9si minta egy olyan taktika, amely szerint k\xc3\xa9sleltetj\xc3\xbck egy objektum l\xc3\xa9trehoz\xc3\xa1s\xc3\xa1t, vagy valamely sz\xc3\xa1m\xc3\xadt\xc3\xa1sig\xc3\xa9nyes m\xc5\xb1velet elv\xc3\xa9gz\xc3\xa9s\xc3\xa9t eg\xc3\xa9szen addig, am\xc3\xadg az objektumra vagy a sz\xc3\xa1m\xc3\xadt\xc3\xa1s eredm\xc3\xa9ny\xc3\xa9re el\xc5\x91sz\xc3\xb6r t\xc3\xa9nylegesen sz\xc3\xbcks\xc3\xa9g lesz._NEWLINE_Ezt tipikusan egy v\xc3\xa1ltoz\xc3\xb3 el\xc3\xa9r\xc3\xa9s\xc3\xa9re szolg\xc3\xa1l\xc3\xb3 elj\xc3\xa1r\xc3\xa1s vagy egy objektum-tulajdons\xc3\xa1g (property) defin\xc3\xadci\xc3\xb3 bevezet\xc3\xa9s\xc3\xa9vel val\xc3\xb3s\xc3\xadtjuk meg, amelyben ellen\xc5\x91rizz\xc3\xbck, hogy az el\xc3\xa9rni (haszn\xc3\xa1lni) k\xc3\xadv\xc3\xa1nt objektum p\xc3\xa9ld\xc3\xa1ny (vagy sz\xc3\xa1m\xc3\xadt\xc3\xa1si eredm\xc3\xa9ny) l\xc3\xa9tezik-e m\xc3\xa1r. Ha nem l\xc3\xa9tezik, egy \xc3\xbaj p\xc3\xa9ld\xc3\xa1ny ker\xc3\xbcl l\xc3\xa9trehoz\xc3\xa1sra \xc3\xa9s t\xc3\xa1rol\xc3\xa1sra a kapcsol\xc3\xb3d\xc3\xb3 v\xc3\xa1ltoz\xc3\xb3ban, \xc3\xa9s ennek \xc3\xa9rt\xc3\xa9ke ker\xc3\xbcl a h\xc3\xadv\xc3\xb3nak (az adatra hivatkoz\xc3\xb3 k\xc3\xb3dr\xc3\xa9szletnek) visszaad\xc3\xa1sra \xe2\x80\x9e\xc3\xa9ppen a kell\xc5\x91 id\xc5\x91ben\xe2\x80\x9d (Just In Time) m\xc3\xb3don._NEWLINE_Ezzel a viselked\xc3\xa9ssel az objektum l\xc3\xa9trehoz\xc3\xa1s\xc3\xa1t \xe2\x80\x9eelhalasztj\xc3\xa1k\xe2\x80\x9d az els\xc5\x91 haszn\xc3\xa1latig, amely bizonyos k\xc3\xb6r\xc3\xbclm\xc3\xa9nyek k\xc3\xb6z\xc3\xb6tt (pl. az objektum ritk\xc3\xa1bb haszn\xc3\xa1lata eset\xc3\xa9n), cs\xc3\xb6kkenti a rendszer v\xc3\xa1laszidej\xc3\xa9t \xc3\xa9s gyors\xc3\xadtja az ind\xc3\xadt\xc3\xa1st az\xc3\xa1ltal, hogy elker\xc3\xbcli a nagym\xc3\xa9ret\xc5\xb1 objektumok el\xc5\x91zetes l\xc3\xa9trehoz\xc3\xa1s\xc3\xa1t \xc3\xa9s mem\xc3\xb3riafoglal\xc3\xa1s\xc3\xa1t. (Megjegyezz\xc3\xbck, hogy ak\xc3\xa1r ellenkez\xc5\x91 hat\xc3\xa1st okozhat az \xc3\xa1ltal\xc3\xa1nos teljes\xc3\xadtm\xc3\xa9nyben, ha a k\xc3\xa9sleltetett objektum l\xc3\xa9trehoz\xc3\xa1s el\xc5\x91nyeit \xe2\x80\x9eelhaszn\xc3\xa1ljuk\xe2\x80\x9d a rendszer ind\xc3\xadt\xc3\xb3/el\xc5\x91k\xc3\xa9sz\xc3\xadt\xc5\x91 f\xc3\xa1zisa sor\xc3\xa1n.)_NEWLINE_T\xc3\xb6bb sz\xc3\xa1lon fut\xc3\xb3 k\xc3\xb3d eset\xc3\xa9n, a lusta inicializ\xc3\xa1ci\xc3\xb3val haszn\xc3\xa1lt objektumokhoz val\xc3\xb3 hozz\xc3\xa1f\xc3\xa9r\xc3\xa9st szinkroniz\xc3\xa1lni kell (k\xc3\xb6lcs\xc3\xb6n\xc3\xb6s kiz\xc3\xa1r\xc3\xa1s/mutex), a versenyhelyzet (race condition) elker\xc3\xbcl\xc3\xa9se \xc3\xa9rdek\xc3\xa9ben._NEWLINE_A k\xc3\xa9sleltetett ki\xc3\xa9rt\xc3\xa9kel\xc3\xa9s j\xc3\xb3l mutatja az alap\xc3\xb6tlet \xc3\xa1ltal\xc3\xa1nos megval\xc3\xb3s\xc3\xadt\xc3\xa1s\xc3\xa1t. Az er\xc5\x91sen imperat\xc3\xadv programoz\xc3\xa1si nyelvekben ez a minta rejtett vesz\xc3\xa9lyeket hordoz, csak\xc3\xbagy mint b\xc3\xa1rmely programoz\xc3\xa1si szok\xc3\xa1s amely megosztott \xc3\xa1llapotokra t\xc3\xa1maszkodik.\n_START_SECTION_\nC\n_START_PARAGRAPH_\nC-ben a lusta inicializ\xc3\xa1ci\xc3\xb3 egyetlen f\xc3\xbcggv\xc3\xa9nyben vagy egyetlen forr\xc3\xa1sf\xc3\xa1jlban ker\xc3\xbcl megval\xc3\xb3s\xc3\xadt\xc3\xa1sra, statikus v\xc3\xa1ltoz\xc3\xb3k haszn\xc3\xa1lat\xc3\xa1val. _NEWLINE_Egy f\xc3\xbcggv\xc3\xa9nyben:_NEWLINE_#include<string.h>#include<stdlib.h>#include<stddef.h>#include<stdio.h>struct fruit {_NEWLINE_    char *name;_NEWLINE_    struct fruit *next;_NEWLINE_    int number;_NEWLINE_    /* Egy\xc3\xa9b adattagok */};struct fruit *get_fruit(char *name) {_NEWLINE_    static struct fruit *fruit_list;_NEWLINE_    static int seq;_NEWLINE_    struct fruit *f;_NEWLINE_    for (f=fruit_list; f; f=f->next)_NEWLINE_        if (0==strcmp(name, f->name))_NEWLINE_            return f;_NEWLINE_    if (!(f = malloc(sizeof(struct fruit))))_NEWLINE_        return NULL;_NEWLINE_    if (!(f->name = strdup(name))) {_NEWLINE_        free(f);_NEWLINE_        return NULL;_NEWLINE_    }_NEWLINE_    f->number = ++seq;_NEWLINE_    f->next = fruit_list;_NEWLINE_    fruit_list = f;_NEWLINE_    return f;}/* P\xc3\xa9lda k\xc3\xb3d */int main(int argc, char *argv[]) {_NEWLINE_    int i;_NEWLINE_    struct fruit *f;_NEWLINE_    if (argc<2) {_NEWLINE_        fprintf(stderr, "Haszn\xc3\xa1lat: fruits gy\xc3\xbcm\xc3\xb6lcs-n\xc3\xa9v [...]\\n");_NEWLINE_        exit(1);_NEWLINE_    }_NEWLINE_    for (i=1; i<argc; i++) {_NEWLINE_        if ((f = get_fruit(argv[i]))) {_NEWLINE_            printf("Gy\xc3\xbcm\xc3\xb6lcs %s: sz\xc3\xa1ma %d\\n", argv[i], f->number);_NEWLINE_        }_NEWLINE_    }_NEWLINE_    return 0;}_NEWLINE_Egyetlen forr\xc3\xa1sf\xc3\xa1jl haszn\xc3\xa1lata a fentiek helyett lehet\xc5\x91v\xc3\xa9 teszi, hogy az \xc3\xa1llapotok megoszt\xc3\xa1sra ker\xc3\xbcljenek t\xc3\xb6bb f\xc3\xbcggv\xc3\xa9ny k\xc3\xb6z\xc3\xb6tt \xc3\xbagy, hogy a nem kapcsol\xc3\xb3d\xc3\xb3 f\xc3\xbcggv\xc3\xa9nyek el\xc5\x91l tov\xc3\xa1bbra is el vannak rejtve. _NEWLINE_fruit.h:_NEWLINE_#ifndef _FRUIT_INCLUDED_#define _FRUIT_INCLUDED_struct fruit {_NEWLINE_    char *name;_NEWLINE_    struct fruit *next;_NEWLINE_    int number;_NEWLINE_    /* Egy\xc3\xa9b adattagok */};struct fruit *get_fruit(char *name);void print_fruit_list(FILE *file);#endif /* _FRUIT_INCLUDED_ */_NEWLINE_fruit.c:_NEWLINE_#include<string.h>#include<stdlib.h>#include<stddef.h>#include<stdio.h>#include"fruit.h"static struct fruit *fruit_list;static int seq;struct fruit *get_fruit(char *name) {_NEWLINE_    struct fruit *f;_NEWLINE_    for (f=fruit_list; f; f=f->next)_NEWLINE_        if (0==strcmp(name, f->name))_NEWLINE_            return f;_NEWLINE_    if (!(f = malloc(sizeof(struct fruit))))_NEWLINE_        return NULL;_NEWLINE_    if (!(f->name = strdup(name))) {_NEWLINE_        free(f);_NEWLINE_        return NULL;_NEWLINE_    }_NEWLINE_    f->number = ++seq;_NEWLINE_    f->next = fruit_list;_NEWLINE_    fruit_list = f;_NEWLINE_    return f;}void print_fruit_list(FILE *file) {_NEWLINE_    struct fruit *f;_NEWLINE_    for (f=fruit_list; f; f=f->next)_NEWLINE_        fprintf(file, "%4d  %s\\n", f->number, f->name);}_NEWLINE_main.c:_NEWLINE_#include<stdlib.h>#include<stdio.h>#include"fruit.h"int main(int argc, char *argv[]) {_NEWLINE_    int i;_NEWLINE_    struct fruit *f;_NEWLINE_    if (argc<2) {_NEWLINE_        fprintf(stderr, "Haszn\xc3\xa1lat: fruits gy\xc3\xbcm\xc3\xb6lcs-n\xc3\xa9v [...]\\n");_NEWLINE_        exit(1);_NEWLINE_    }_NEWLINE_    for (i=1; i<argc; i++) {_NEWLINE_        if ((f = get_fruit(argv[i]))) {_NEWLINE_            printf("Gy\xc3\xbcm\xc3\xb6lcs %s: sz\xc3\xa1ma %d\\n", argv[i], f->number);_NEWLINE_        }_NEWLINE_    }_NEWLINE_    printf("A k\xc3\xb6vetkez\xc5\x91 gy\xc3\xbcm\xc3\xb6lcs\xc3\xb6k (fruits) gener\xc3\xa1l\xc3\xb3dtak:\\n");_NEWLINE_    print_fruit_list(stdout);_NEWLINE_    return 0;}\n_START_SECTION_\nC#\n_START_PARAGRAPH_\nA .NET 4.0-ban a Microsoft el\xc3\xa9rhet\xc5\x91v\xc3\xa9 tett egy Lazy oszt\xc3\xa1lyt, amely lusta (k\xc3\xa9s\xc5\x91i) bet\xc3\xb6lt\xc3\xa9shez haszn\xc3\xa1lhat\xc3\xb3. Az al\xc3\xa1bbi n\xc3\xa9h\xc3\xa1ny sor mintak\xc3\xb3d a Fruit oszt\xc3\xa1ly lusta bet\xc3\xb6lt\xc3\xa9s\xc3\xa9t mutatja:_NEWLINE_Lazy<Fruit> lazyFruit = new Lazy<Fruit>();Fruit fruit = lazyFruit.Value;_NEWLINE_Az al\xc3\xa1bbi egy minta k\xc3\xb3d C# programoz\xc3\xa1si nyelven._NEWLINE_A Fruit oszt\xc3\xa1ly maga nem csin\xc3\xa1l semmit a p\xc3\xa9ld\xc3\xa1ban, a _typesDictionary oszt\xc3\xa1ly-v\xc3\xa1ltoz\xc3\xb3 egy sz\xc3\xb3t\xc3\xa1r/asszociat\xc3\xadv t\xc3\xb6mb amiben a Fruit p\xc3\xa9ld\xc3\xa1nyokat t\xc3\xa1roljuk a typeName (t\xc3\xadpusn\xc3\xa9v) alapj\xc3\xa1n._NEWLINE_using System;using System.Collections;using System.Collections.Generic;public class Fruit{_NEWLINE_    private string _typeName;_NEWLINE_    private static Dictionary<string, Fruit> _typesDictionary = new Dictionary<string, Fruit>();_NEWLINE__NEWLINE_    private Fruit(String typeName)_NEWLINE_    {_NEWLINE_        this._typeName = typeName;_NEWLINE_    }_NEWLINE__NEWLINE_    public static Fruit GetFruitByTypeName(string type)_NEWLINE_    {_NEWLINE_        Fruit fruit;_NEWLINE__NEWLINE_        if (!_typesDictionary.TryGetValue(type, out fruit))_NEWLINE_        {_NEWLINE_            // Lusta inicializ\xc3\xa1ci\xc3\xb3_NEWLINE_            fruit = new Fruit(type);_NEWLINE__NEWLINE_            _typesDictionary.Add(type, fruit);_NEWLINE_        }_NEWLINE_        return fruit;_NEWLINE_    }_NEWLINE__NEWLINE_    public static void ShowAll()_NEWLINE_    {_NEWLINE_        if (_typesDictionary.Count > 0)_NEWLINE_        {_NEWLINE_            Console.WriteLine("Az elk\xc3\xa9sz\xc3\xadtett p\xc3\xa9ld\xc3\xa1nyok sz\xc3\xa1ma = {0}", _typesDictionary.Count);_NEWLINE_            _NEWLINE_            foreach (KeyValuePair<string, Fruit> kvp in _typesDictionary)_NEWLINE_            {_NEWLINE_                Console.WriteLine(kvp.Key);_NEWLINE_            }_NEWLINE_            _NEWLINE_            Console.WriteLine();_NEWLINE_        }_NEWLINE_    }_NEWLINE_    _NEWLINE_    public Fruit()_NEWLINE_    {_NEWLINE_        // sz\xc3\xbcks\xc3\xa9ges a mintak\xc3\xb3d leford\xc3\xadt\xc3\xa1s\xc3\xa1hoz_NEWLINE_    }}class Program{_NEWLINE_    static void Main(string[] args)_NEWLINE_    {_NEWLINE_        Fruit.GetFruitByTypeName("Banana");_NEWLINE_        Fruit.ShowAll();_NEWLINE__NEWLINE_        Fruit.GetFruitByTypeName("Apple");_NEWLINE_        Fruit.ShowAll();_NEWLINE__NEWLINE_        // az el\xc5\x91z\xc5\x91leg m\xc3\xa1r l\xc3\xa9trehozott p\xc3\xa9ld\xc3\xa1nyt adja vissza _NEWLINE_        // ami a "Banana" param\xc3\xa9terrel val\xc3\xb3 els\xc5\x91 h\xc3\xadv\xc3\xa1sn\xc3\xa1l l\xc3\xa9trej\xc3\xb6tt_NEWLINE_        Fruit.GetFruitByTypeName("Banana");_NEWLINE_        Fruit.ShowAll();_NEWLINE__NEWLINE_        Console.ReadLine();_NEWLINE_    }}_NEWLINE_Az al\xc3\xa1bbiakban egy meglehet\xc5\x91sen l\xc3\xa9nyegre t\xc3\xb6r\xc5\x91 p\xc3\xa9ld\xc3\xa1j\xc3\xa1t mutatjuk be a lusta inicializ\xc3\xa1ci\xc3\xb3 programtervez\xc3\xa9si mint\xc3\xa1nak azzal, hogy a p\xc3\xa9lda enumer\xc3\xa1ci\xc3\xb3t (felsorol\xc3\xa1ssal defini\xc3\xa1lt t\xc3\xadpust) haszn\xc3\xa1l alkalmazott t\xc3\xadpusk\xc3\xa9nt._NEWLINE_//IVSR: LazyInitialization design patternnamespace IVSR.DesignPatterns.LazyInitialization{_NEWLINE_    public class LazyFactoryObject_NEWLINE_    {_NEWLINE_        // az elemek bels\xc5\x91leg haszn\xc3\xa1lt gy\xc5\xb1jtem\xc3\xa9nye._NEWLINE_        // az IDictionary t\xc3\xadpus gondoskodik r\xc3\xb3la, hogy az elemek egyediek legyenek_NEWLINE_        private IDictionary<LazyObjectType, LazyObject> _LazyObjectList = _NEWLINE_            new Dictionary<LazyObjectType, LazyObject>();_NEWLINE__NEWLINE_        // felsorol\xc3\xa1si t\xc3\xadpus a k\xc3\xadv\xc3\xa1nt t\xc3\xadpusnevek megad\xc3\xa1s\xc3\xa1hoz._NEWLINE_        // \xc3\xadgy nem sz\xc3\xbcks\xc3\xa9ges string param\xc3\xa9ter\xc3\xa1tad\xc3\xa1st, _NEWLINE_        // \xc3\xa9s lehets\xc3\xa9ges a ford\xc3\xadt\xc3\xa1skori t\xc3\xadpusellen\xc5\x91rz\xc3\xa9s_NEWLINE_        public enum LazyObjectType_NEWLINE_        { _NEWLINE_            None,_NEWLINE_            Small,_NEWLINE_            Big,_NEWLINE_            Bigger,_NEWLINE_            Huge_NEWLINE_        }_NEWLINE__NEWLINE_        // egy \xc3\xa1ltal\xc3\xa1nos t\xc3\xadpus a l\xc3\xa9trehozand\xc3\xb3 objektumoknak_NEWLINE_        public struct LazyObject_NEWLINE_        {_NEWLINE_            public LazyObjectType Name;_NEWLINE_            public IList<int> Result;_NEWLINE_        }_NEWLINE__NEWLINE_        // egy felsorol\xc3\xa1si t\xc3\xadpus elemet vesz \xc3\xa1t, \xc3\xa9s l\xc3\xa9trehoz egy _NEWLINE_        // \'dr\xc3\xa1ga\' (id\xc5\x91ig\xc3\xa9nyes, sz\xc3\xa1m\xc3\xadt\xc3\xa1sig\xc3\xa9nyes stb.) list\xc3\xa1t_NEWLINE_        private IList<int> Result(LazyObjectType name)_NEWLINE_        {_NEWLINE_            IList<int> result = null;_NEWLINE__NEWLINE_            switch (name)_NEWLINE_            { _NEWLINE_                case LazyObjectType.Small:_NEWLINE_                    result = CreateSomeExpensiveList(1, 100);_NEWLINE_                    break;_NEWLINE_                case LazyObjectType.Big:_NEWLINE_                    result = CreateSomeExpensiveList(1, 1000);_NEWLINE_                    break;_NEWLINE_                case LazyObjectType.Bigger:_NEWLINE_                    result = CreateSomeExpensiveList(1, 10000);_NEWLINE_                    break;_NEWLINE_                case LazyObjectType.Huge:_NEWLINE_                    result = CreateSomeExpensiveList(1, 100000);_NEWLINE_                    break;_NEWLINE_                case LazyObjectType.None:_NEWLINE_                    result = null;_NEWLINE_                    break;_NEWLINE_                default:_NEWLINE_                    result = null;_NEWLINE_                    break;_NEWLINE_            }_NEWLINE__NEWLINE_            return result;_NEWLINE_        }_NEWLINE__NEWLINE_        // nem lenne \'dr\xc3\xa1ga\' (sz\xc3\xa1m\xc3\xadt\xc3\xa1sig\xc3\xa9nyes) l\xc3\xa9trehozni az elemet _NEWLINE_        // de hogy \xc3\xa9rthet\xc5\x91 legyen a l\xc3\xa9nyeg, k\xc3\xa9sleltetj\xc3\xbck n\xc3\xa9h\xc3\xa1ny _NEWLINE_        // sz\xc3\xa1m\xc3\xadt\xc3\xa1sig\xc3\xa9nyes objektum l\xc3\xa9trehoz\xc3\xa1s\xc3\xa1t addig, _NEWLINE_        // am\xc3\xadg sz\xc3\xbcks\xc3\xa9g nem lesz r\xc3\xa1juk_NEWLINE_        private IList<int> CreateSomeExpensiveList(int start, int end)_NEWLINE_        {_NEWLINE_            IList<int> result = new List<int>();_NEWLINE__NEWLINE_            for (int counter = 0; counter < (end - start); counter++)_NEWLINE_            {_NEWLINE_                result.Add(start + counter);_NEWLINE_            }_NEWLINE__NEWLINE_            return result;_NEWLINE_        }_NEWLINE__NEWLINE_        public LazyFactoryObject()_NEWLINE_        { _NEWLINE_            // \xc3\xbcres konstruktor_NEWLINE_        }_NEWLINE__NEWLINE_        public LazyObject GetLazyFactoryObject(LazyObjectType name)_NEWLINE_        {_NEWLINE_            LazyObject noGoodSomeOne;_NEWLINE__NEWLINE_            // \'el\xc5\x91veszi\' a LazyObjectType elemet a list\xc3\xa1r\xc3\xb3l ha van m\xc3\xa1r ott,_NEWLINE_            // egy\xc3\xa9bk\xc3\xa9nt (ha nincs) l\xc3\xa9trehoz egyet \xc3\xa9s a list\xc3\xa1ra (is) teszi_NEWLINE_            if (!_LazyObjectList.TryGetValue(name, out noGoodSomeOne))_NEWLINE_            {_NEWLINE_                noGoodSomeOne = new LazyObject();_NEWLINE_                noGoodSomeOne.Name = name;_NEWLINE_                noGoodSomeOne.Result = this.Result(name);_NEWLINE__NEWLINE_                _LazyObjectList.Add(name, noGoodSomeOne);_NEWLINE_            }_NEWLINE__NEWLINE_            return noGoodSomeOne;_NEWLINE_        }_NEWLINE_    }}\n_START_SECTION_\nC++\n_START_PARAGRAPH_\nAz al\xc3\xa1bbiakban egy C++ p\xc3\xa9lda._NEWLINE_#include <iostream>#include <string>#include <map>_NEWLINE_ _NEWLINE_using namespace std;_NEWLINE_ _NEWLINE_class Fruit {_NEWLINE_    public:_NEWLINE_        static Fruit* getFruit(const string& type);_NEWLINE_        static void printCurrentTypes();_NEWLINE__NEWLINE_    private:_NEWLINE_        static map<string,Fruit*> types;_NEWLINE_        string type;_NEWLINE__NEWLINE_        // megjegyz\xc3\xa9s: a priv\xc3\xa1t konstruktor kik\xc3\xa9nyszer\xc3\xadti, hogy a statikus _NEWLINE_        // getFruit() f\xc3\xbcggv\xc3\xa9nnyel kelljen objektum p\xc3\xa9ld\xc3\xa1nyt l\xc3\xa9trehozni_NEWLINE_        Fruit(const string& t) : type( t ) {}};// sz\xc3\xbcks\xc3\xa9ges defin\xc3\xadci\xc3\xb3 a statikus tag-v\xc3\xa1ltoz\xc3\xb3 haszn\xc3\xa1lat\xc3\xa1hozmap<string,Fruit*> Fruit::types;        _NEWLINE_ _NEWLINE_/* * Lusta gy\xc3\xa1rt\xc3\xb3 met\xc3\xb3dus, azt a \'Fruit\' p\xc3\xa9ld\xc3\xa1nyt veszi el\xc5\x91, amire a param\xc3\xa9terk\xc3\xa9nt * \xc3\xa1tadott n\xc3\xa9vvel hivatkoztak. L\xc3\xa9trehoz egy \xc3\xbaj p\xc3\xa9ld\xc3\xa1nyt, ha sz\xc3\xbcks\xc3\xa9ges. * el\xc5\x91felt\xc3\xa9tel: a \'type\' param\xc3\xa9ter valamilyen gy\xc3\xbcm\xc3\xb6lcs n\xc3\xa9v legyen pl. "alma" * ut\xc3\xb3felt\xc3\xa9tel: visszaadja a \'Fruit\' p\xc3\xa9ld\xc3\xa1nyt, amire a n\xc3\xa9vvel hivatkoztunk */Fruit* Fruit::getFruit(const string& type) {_NEWLINE_    // pr\xc3\xb3b\xc3\xa1lunk keresni egy l\xc3\xa9tez\xc5\x91 p\xc3\xa9ld\xc3\xa1nyt; ha nem tal\xc3\xa1lunk, _NEWLINE_    // az std::map f\xc3\xbcggv\xc3\xa9ny \'types.end()\' \xc3\xa9rt\xc3\xa9ket ad vissza_NEWLINE_    map<string,Fruit*>::iterator it = types.find(type);  _NEWLINE_ _NEWLINE_    Fruit *f;_NEWLINE_    if (it == types.end()) { _NEWLINE_        // ha nem tal\xc3\xa1ltunk p\xc3\xa9ld\xc3\xa1nyt a k\xc3\xa9rt t\xc3\xadpusb\xc3\xb3l, hozzunk l\xc3\xa9tre egyet_NEWLINE_        f = new Fruit(type); // lusta inicializ\xc3\xa1ci\xc3\xb3s r\xc3\xa9sz_NEWLINE_        // hozz\xc3\xa1adjuk az \xc3\xbajonnan l\xc3\xa9trehozott \'Fruit\' p\xc3\xa9ld\xc3\xa1nyt _NEWLINE_        // a \'types\' asszociat\xc3\xadv t\xc3\xb6mbh\xc3\xb6z, hogy k\xc3\xa9s\xc5\x91bb megtal\xc3\xa1ljuk_NEWLINE_        types[type] = f;     _NEWLINE_    } else { // ha m\xc3\xa1r van ilyen p\xc3\xa9ld\xc3\xa1nyunk_NEWLINE_        // a visszaadott \xc3\xa9rt\xc3\xa9k a megtal\xc3\xa1lt \'Fruit\' p\xc3\xa9ld\xc3\xa1ny lesz_NEWLINE_        f = it->second; _NEWLINE_    }_NEWLINE_    return f;}/* * P\xc3\xa9ldak\xc3\xa9nt l\xc3\xa1ssuk a minta haszn\xc3\xa1lat\xc3\xa1t */void Fruit::printCurrentTypes() {_NEWLINE_    if (!types.empty()) {_NEWLINE_        cout << "A l\xc3\xa9trehozott p\xc3\xa9ld\xc3\xa1nyok sz\xc3\xa1ma = " << types.size() << endl;_NEWLINE_        for (map<string,Fruit*>::iterator iter = types.begin(); iter != types.end(); ++iter) {_NEWLINE_            cout << (*iter).first << endl;_NEWLINE_        }_NEWLINE_        cout << endl;_NEWLINE_    }}int main(void) {_NEWLINE_    Fruit::getFruit("Banana");_NEWLINE_    Fruit::printCurrentTypes();_NEWLINE_ _NEWLINE_    Fruit::getFruit("Apple");_NEWLINE_    Fruit::printCurrentTypes();_NEWLINE_ _NEWLINE_    // az el\xc5\x91z\xc5\x91leg m\xc3\xa1r l\xc3\xa9trehozott p\xc3\xa9ld\xc3\xa1nyt adja vissza _NEWLINE_    // ami a "Banana" param\xc3\xa9terrel val\xc3\xb3 els\xc5\x91 h\xc3\xadv\xc3\xa1sn\xc3\xa1l l\xc3\xa9trej\xc3\xb6tt_NEWLINE_    Fruit::getFruit("Banana");_NEWLINE_    Fruit::printCurrentTypes();_NEWLINE_ _NEWLINE_    return 0;}/*KIMENET:A l\xc3\xa9trehozott p\xc3\xa9ld\xc3\xa1nyok sz\xc3\xa1ma = 1Banana A l\xc3\xa9trehozott p\xc3\xa9ld\xc3\xa1nyok sz\xc3\xa1ma = 2AppleBanana A l\xc3\xa9trehozott p\xc3\xa9ld\xc3\xa1nyok sz\xc3\xa1ma = 2AppleBanana*/\n_START_SECTION_\nJava\n_START_PARAGRAPH_\nAz al\xc3\xa1bbiakban egy Java p\xc3\xa9ld\xc3\xa1t mutatunk be._NEWLINE_import java.util.HashMap;import java.util.Map;import java.util.Map.Entry;public class Program {_NEWLINE__NEWLINE_    /**     * @param args     */_NEWLINE_    public static void main(String[] args) {_NEWLINE_        Fruit.getFruitByTypeName(FruitType.BANANA);_NEWLINE_        Fruit.showAll();_NEWLINE_        Fruit.getFruitByTypeName(FruitType.APPLE);_NEWLINE_        Fruit.showAll();_NEWLINE_        Fruit.getFruitByTypeName(FruitType.BANANA);_NEWLINE_        Fruit.showAll();_NEWLINE_    }}enum FruitType {_NEWLINE_    NONE,_NEWLINE_    APPLE,_NEWLINE_    BANANA,}class Fruit {_NEWLINE__NEWLINE_    private static Map<FruitType, Fruit> types = new HashMap<>();_NEWLINE_    _NEWLINE_    /**     * A priv\xc3\xa1t konstruktor kik\xc3\xa9nyszer\xc3\xadti a gy\xc3\xa1rt\xc3\xb3 met\xc3\xb3dus haszn\xc3\xa1lat\xc3\xa1t.     * @param type     */_NEWLINE_    private Fruit(FruitType type) {_NEWLINE_    }_NEWLINE_    _NEWLINE_    /**     * Lusta gy\xc3\xa1rt\xc3\xb3 met\xc3\xb3dus, azt a \'Fruit\' p\xc3\xa9ld\xc3\xa1nyt veszi el\xc5\x91, amire a param\xc3\xa9terrel     * hivatkoztak. L\xc3\xa9trehoz egy \xc3\xbaj p\xc3\xa9ld\xc3\xa1nyt, ha sz\xc3\xbcks\xc3\xa9ges.     * @param type B\xc3\xa1rmilyen a t\xc3\xadpusn\xc3\xa1l megengedett gy\xc3\xbcm\xc3\xb6lcs n\xc3\xa9v, pl. APPLE     * @return A \'Fruit\' p\xc3\xa9ld\xc3\xa1ny, amire a t\xc3\xadpus-elem n\xc3\xa9vvel hivatkoztunk     */_NEWLINE_    public static Fruit getFruitByTypeName(FruitType type) {_NEWLINE_        Fruit fruit;_NEWLINE_        // Ennek a programr\xc3\xa9sznek konkurencia probl\xc3\xa9m\xc3\xa1i lehetnek._NEWLINE_        // Az al\xc3\xa1bbiakban a \'types\'-hoz val\xc3\xb3 hozz\xc3\xa1f\xc3\xa9r\xc3\xa9s nem szinkroniz\xc3\xa1lt, _NEWLINE_        // \xc3\xadgy a \'types.put\' \xc3\xa9s a \'types.containsKey\' egyszerre is megh\xc3\xadv\xc3\xa1sra ker\xc3\xbclhet._NEWLINE_        // Nem kell meglep\xc5\x91dni, ha az adatok s\xc3\xa9r\xc3\xbclnek... :)_NEWLINE_        if (!types.containsKey(type)) {_NEWLINE_            // Lusta inicializ\xc3\xa1ci\xc3\xb3_NEWLINE_            fruit = new Fruit(type);_NEWLINE_            types.put(type, fruit);_NEWLINE_        } else {_NEWLINE_            // OK, m\xc3\xa1r el\xc3\xa9rhet\xc5\x91_NEWLINE_            fruit = types.get(type);_NEWLINE_        }_NEWLINE_        _NEWLINE_        return fruit;_NEWLINE_    }_NEWLINE_    _NEWLINE_    /**     * Lusta gy\xc3\xa1rt\xc3\xb3 met\xc3\xb3dus, azt a \'Fruit\' p\xc3\xa9ld\xc3\xa1nyt veszi el\xc5\x91, amire a param\xc3\xa9terrel     * hivatkoztak. L\xc3\xa9trehoz egy \xc3\xbaj p\xc3\xa9ld\xc3\xa1nyt, ha sz\xc3\xbcks\xc3\xa9ges. Dupl\xc3\xa1n ellen\xc5\x91rz\xc3\xb6tt lockol\xc3\xa1s     * mint\xc3\xa1t haszn\xc3\xa1l a konkurens hozz\xc3\xa1f\xc3\xa9r\xc3\xa9s biztons\xc3\xa1goss\xc3\xa1 t\xc3\xa9tel\xc3\xa9re.     * @param type B\xc3\xa1rmilyen a t\xc3\xadpusn\xc3\xa1l megengedett gy\xc3\xbcm\xc3\xb6lcs n\xc3\xa9v, pl. APPLE     * @return A \'Fruit\' p\xc3\xa9ld\xc3\xa1ny, amire a t\xc3\xadpus-elem n\xc3\xa9vvel hivatkoztunk     */_NEWLINE_    public static Fruit getFruitByTypeNameHighConcurrentVersion(FruitType type) {_NEWLINE_        if (!types.containsKey(type)) {_NEWLINE_            synchronized (types) {_NEWLINE_                // \xc3\x9ajra ellen\xc5\x91rizz\xc3\xbck a \'type\' l\xc3\xa9tez\xc3\xa9s\xc3\xa9t, miut\xc3\xa1n lockoltuk a \'types\'-t_NEWLINE_                // hogy biztosak legy\xc3\xbcnk benne, hogy nem ker\xc3\xbclt id\xc5\x91k\xc3\xb6zben l\xc3\xa9trehoz\xc3\xa1sra_NEWLINE_                // bel\xc5\x91le p\xc3\xa9ld\xc3\xa1ny egy m\xc3\xa1sik programsz\xc3\xa1lon_NEWLINE_                if (!types.containsKey(type)) {_NEWLINE_                    // Lusta inicializ\xc3\xa1ci\xc3\xb3_NEWLINE_                    types.put(type, new Fruit(type));_NEWLINE_                }_NEWLINE_            }_NEWLINE_        }_NEWLINE_        _NEWLINE_        return types.get(type);_NEWLINE_    }_NEWLINE_    _NEWLINE_    /**     * Ki\xc3\xadrja az \xc3\xb6sszes l\xc3\xa9trehozott \'Fruit\' p\xc3\xa9ld\xc3\xa1nyt.     */_NEWLINE_    public static void showAll() {_NEWLINE_        if (types.size() > 0) {_NEWLINE_ _NEWLINE_           System.out.println("A l\xc3\xa9trehozott p\xc3\xa9ld\xc3\xa1nyok sz\xc3\xa1ma = " + types.size());_NEWLINE_            _NEWLINE_            for (Entry<FruitType, Fruit> entry : types.entrySet()) {_NEWLINE_                String fruit = entry.getKey().toString();_NEWLINE_                fruit = Character.toUpperCase(fruit.charAt(0)) + fruit.substring(1);_NEWLINE_                System.out.println(fruit);_NEWLINE_            }_NEWLINE_            _NEWLINE_            System.out.println();_NEWLINE_        }_NEWLINE_    }}_NEWLINE_Kimenet_NEWLINE_A l\xc3\xa9trehozott p\xc3\xa9ld\xc3\xa1nyok sz\xc3\xa1ma = 1_NEWLINE_Banana_NEWLINE__NEWLINE_A l\xc3\xa9trehozott p\xc3\xa9ld\xc3\xa1nyok sz\xc3\xa1ma = 2_NEWLINE_Banana_NEWLINE_Apple_NEWLINE__NEWLINE_A l\xc3\xa9trehozott p\xc3\xa9ld\xc3\xa1nyok sz\xc3\xa1ma = 2_NEWLINE_Banana_NEWLINE_Apple\n_START_SECTION_\nJavaScript\n_START_PARAGRAPH_\nAz al\xc3\xa1bbiakban egy JavaScript p\xc3\xa9lda._NEWLINE_var Fruit = (function() {_NEWLINE_  var types = {};_NEWLINE_  function Fruit() {};_NEWLINE__NEWLINE_  // visszaadja a param\xc3\xa9terk\xc3\xa9nt kapott objektum _NEWLINE_  // tulajdons\xc3\xa1gainak(property) sz\xc3\xa1m\xc3\xa1t_NEWLINE_  function count(obj) {_NEWLINE_    return Object.keys(obj).length;_NEWLINE_  }_NEWLINE__NEWLINE_  var _static = {_NEWLINE_    getFruit: function(type) {_NEWLINE_      if (typeof types[type] == \'undefined\') {_NEWLINE_        types[type] = new Fruit;_NEWLINE_      }_NEWLINE_      return types[type];_NEWLINE_    },_NEWLINE_    printCurrentTypes: function () {_NEWLINE_      console.log(\'A l\xc3\xa9trehozott p\xc3\xa9ld\xc3\xa1nyok sz\xc3\xa1ma: \' + count(types));_NEWLINE_      for (var type in types) {_NEWLINE_        console.log(type);_NEWLINE_      }_NEWLINE_    }_NEWLINE_  };_NEWLINE__NEWLINE_  return _static;})();Fruit.getFruit(\'Apple\');Fruit.printCurrentTypes();Fruit.getFruit(\'Banana\');Fruit.printCurrentTypes();Fruit.getFruit(\'Apple\');Fruit.printCurrentTypes();_NEWLINE_Kimenet_NEWLINE_A l\xc3\xa9trehozott p\xc3\xa9ld\xc3\xa1nyok sz\xc3\xa1ma: 1_NEWLINE_Apple_NEWLINE__NEWLINE_A l\xc3\xa9trehozott p\xc3\xa9ld\xc3\xa1nyok sz\xc3\xa1ma: 2_NEWLINE_Apple_NEWLINE_Banana_NEWLINE__NEWLINE_A l\xc3\xa9trehozott p\xc3\xa9ld\xc3\xa1nyok sz\xc3\xa1ma: 2_NEWLINE_Apple_NEWLINE_Banana\n_START_SECTION_\nPHP\n_START_PARAGRAPH_\nAz al\xc3\xa1bbiakban egy p\xc3\xa9lda a lusta inicializ\xc3\xa1ci\xc3\xb3ra PHP 5-ben:_NEWLINE_<?phpheader(\'Content-type:text/plain; charset=utf-8\');class Fruit {_NEWLINE_    private $type;_NEWLINE_    private static $types = array();_NEWLINE__NEWLINE_    private function __construct($type) {_NEWLINE_        $this->type = $type;_NEWLINE_    }_NEWLINE__NEWLINE_    public static function getFruit($type) {_NEWLINE_        // A lusta inicializ\xc3\xa1ci\xc3\xb3 itt t\xc3\xb6rt\xc3\xa9nik_NEWLINE_        if (!isset(self::$types[$type])) {_NEWLINE_            self::$types[$type] = new Fruit($type);_NEWLINE_        }_NEWLINE__NEWLINE_        return self::$types[$type];_NEWLINE_    }_NEWLINE__NEWLINE_    public static function printCurrentTypes() {_NEWLINE_        echo \'A l\xc3\xa9trehozott p\xc3\xa9ld\xc3\xa1nyok sz\xc3\xa1ma: \' . count(self::$types) . "\\n";_NEWLINE_        foreach (array_keys(self::$types) as $key) {_NEWLINE_            echo "$key\\n";_NEWLINE_        }_NEWLINE_        echo "\\n";_NEWLINE_    }}Fruit::getFruit(\'Apple\');Fruit::printCurrentTypes();Fruit::getFruit(\'Banana\');Fruit::printCurrentTypes();Fruit::getFruit(\'Apple\');Fruit::printCurrentTypes();/*KIMENET:A l\xc3\xa9trehozott p\xc3\xa9ld\xc3\xa1nyok sz\xc3\xa1ma: 1AppleA l\xc3\xa9trehozott p\xc3\xa9ld\xc3\xa1nyok sz\xc3\xa1ma: 2AppleBananaA l\xc3\xa9trehozott p\xc3\xa9ld\xc3\xa1nyok sz\xc3\xa1ma: 2AppleBanana*/?>\n_START_SECTION_\nPython\n_START_PARAGRAPH_\nAz al\xc3\xa1bbiakban egy p\xc3\xa9lda Python programoz\xc3\xa1si nyelven (2.x verzi\xc3\xb3j\xc3\xba Python)._NEWLINE_class Fruit:_NEWLINE_    def __init__(self, sort):_NEWLINE_        self.sort = sort_NEWLINE_    _NEWLINE_class Fruits:_NEWLINE_    def __init__(self):_NEWLINE_        self.sorts = {}_NEWLINE_    _NEWLINE_    def get_fruit(self, sort):_NEWLINE_        if sort not in self.sorts:_NEWLINE_            self.sorts[sort] = Fruit(sort)_NEWLINE_        _NEWLINE_        return self.sorts[sort]if __name__ == \'__main__\':_NEWLINE_    fruits = Fruits()_NEWLINE_    print fruits.get_fruit(\'Apple\')_NEWLINE_    print fruits.get_fruit(\'Lime\')\n_START_SECTION_\nRuby\n_START_PARAGRAPH_\nAz al\xc3\xa1bbiakban egy p\xc3\xa9lda Ruby nyelven, egy t\xc3\xa1voli szolg\xc3\xa1ltat\xc3\xa1st\xc3\xb3l sz\xc3\xa1rmaz\xc3\xb3 (mint pl. a Google-\xc3\xa9) autentik\xc3\xa1ci\xc3\xb3s token lusta inicializ\xc3\xa1l\xc3\xa1s\xc3\xa1ra._NEWLINE_require \'net/http\'class Blogger_NEWLINE_  def auth_token_NEWLINE_    @auth_token ||=_NEWLINE_      (res = Net::HTTP.post_form(uri, params)) &&_NEWLINE_      get_token_from_http_response(res)_NEWLINE_  end_NEWLINE__NEWLINE_  # a \'get_token_from_http_response\', az \'uri\' \xc3\xa9s a \'params\' k\xc3\xa9s\xc5\x91bb vannak defini\xc3\xa1lva az oszt\xc3\xa1lybanendb = Blogger.newb.instance_variable_get(:@auth_token) # nil \xc3\xa9rt\xc3\xa9ket ad visszab.auth_token # a tokent adja visszab.instance_variable_get(:@auth_token) # a tokent adja vissza\n_START_SECTION_\nSmalltalk\n_START_PARAGRAPH_\nAz al\xc3\xa1bbiakban egy Smalltalk nyelv\xc5\xb1 p\xc3\xa9lda, egy tipikus v\xc3\xa1ltoz\xc3\xb3-el\xc3\xa9r\xc3\xa9st biztos\xc3\xadt\xc3\xb3 met\xc3\xb3dusra, amely a v\xc3\xa1ltoz\xc3\xb3 \xc3\xa9rt\xc3\xa9k\xc3\xa9t lusta inicializ\xc3\xa1ci\xc3\xb3 haszn\xc3\xa1lat\xc3\xa1val adja vissza._NEWLINE_    height_NEWLINE_        ^height ifNil: [height := 2.0]._NEWLINE_A fentiek \'nem-lusta\' alternat\xc3\xadv\xc3\xa1ja egy inicializ\xc3\xa1ci\xc3\xb3s met\xc3\xb3dus haszn\xc3\xa1lata, ami m\xc3\xa1r akkor lefut, amikor az objektum l\xc3\xa9trej\xc3\xb6n. Ebben az esetben egy egyszer\xc5\xb1bb v\xc3\xa1ltoz\xc3\xb3-el\xc3\xa9r\xc3\xa9sre szolg\xc3\xa1l\xc3\xb3 met\xc3\xb3dus haszn\xc3\xa1lhat\xc3\xb3 az \xc3\xa9rt\xc3\xa9k kiolvas\xc3\xa1s\xc3\xa1ra._NEWLINE_    initialize_NEWLINE_        height := 2.0_NEWLINE__NEWLINE_    height_NEWLINE_        ^height_NEWLINE_Megjegyezz\xc3\xbck, hogy a lusta inicializ\xc3\xa1ci\xc3\xb3 a nem objektumorient\xc3\xa1lt nyelvekben is haszn\xc3\xa1lhat\xc3\xb3.\n_START_SECTION_\nScala\n_START_PARAGRAPH_\nA Scala programoz\xc3\xa1si nyelvnek be\xc3\xa9p\xc3\xadtett t\xc3\xa1mogat\xc3\xa1sa van a lusta v\xc3\xa1ltoz\xc3\xb3 inicializ\xc3\xa1ci\xc3\xb3hoz._NEWLINE_ 1  scala> val x = { println("Hello"); 99 } 2  Hello 3  x: Int = 99 4  scala> lazy val y = { println("Hello!!"); 31 } 5  y: Int = <lazy> 6  scala> y 7  Hello!! 8  res2: Int = 31 9  scala> y10  res3: Int = 31\n_START_SECTION_\nFord\xc3\xadt\xc3\xa1s\n_START_PARAGRAPH_\nEz a sz\xc3\xb3cikk r\xc3\xa9szben vagy eg\xc3\xa9szben  a   Lazy initialization c\xc3\xadm\xc5\xb1 angol Wikip\xc3\xa9dia-sz\xc3\xb3cikk ezen v\xc3\xa1ltozat\xc3\xa1nak ford\xc3\xadt\xc3\xa1s\xc3\xa1n alapul.  Az eredeti cikk szerkeszt\xc5\x91it annak lapt\xc3\xb6rt\xc3\xa9nete sorolja fel.'