{"id":22513866,"url":"https://github.com/emahtab/factory-design-pattern","last_synced_at":"2026-01-07T01:42:45.680Z","repository":{"id":79525484,"uuid":"460681975","full_name":"eMahtab/factory-design-pattern","owner":"eMahtab","description":null,"archived":false,"fork":false,"pushed_at":"2022-02-18T13:49:07.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-02T03:25:44.265Z","etag":null,"topics":["design-pattern","factory-pattern"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eMahtab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-18T02:28:33.000Z","updated_at":"2022-07-02T16:37:46.000Z","dependencies_parsed_at":"2023-05-10T17:15:33.837Z","dependency_job_id":null,"html_url":"https://github.com/eMahtab/factory-design-pattern","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Ffactory-design-pattern","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Ffactory-design-pattern/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Ffactory-design-pattern/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Ffactory-design-pattern/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eMahtab","download_url":"https://codeload.github.com/eMahtab/factory-design-pattern/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245952136,"owners_count":20699432,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["design-pattern","factory-pattern"],"created_at":"2024-12-07T03:14:44.910Z","updated_at":"2026-01-07T01:42:45.638Z","avatar_url":"https://github.com/eMahtab.png","language":null,"readme":"# Factory Pattern\n\nBelow is the Code from Java 1.8 JDK\n\nCalendar is an abstract class which have subclasses e.g. `GregorianCalendar` and `JapaneseImperialCalendar`.\nAlso Calendar class have overloaded static `getInstance()` method, and one static `createCalendar()` method.\nThe `getInstance()` method finally calls the `createCalendar()` method.\n\n`createCalendar()` method returns the concrete Calendar instance e.g. `GregorianCalendar` or `JapaneseImperialCalendar` etc. depending on the `TimeZone` and `Locale` info passed to `createCalendar()` method.\n\n```java\n\nCalendar is an Abstract class\n\npublic abstract class Calendar implements Serializable, Cloneable, Comparable\u003cCalendar\u003e {\n\n\n    public static Calendar getInstance()\n    {\n        return createCalendar(TimeZone.getDefault(), Locale.getDefault(Locale.Category.FORMAT));\n    }\n    \n    public static Calendar getInstance(TimeZone zone)\n    {\n        return createCalendar(zone, Locale.getDefault(Locale.Category.FORMAT));\n    }\n    \n    public static Calendar getInstance(Locale aLocale)\n    {\n        return createCalendar(TimeZone.getDefault(), aLocale);\n    }\n    \n    public static Calendar getInstance(TimeZone zone, Locale aLocale)\n    {\n        return createCalendar(zone, aLocale);\n    }\n    \n    \n    private static Calendar createCalendar(TimeZone zone, Locale aLocale)\n    {\n        CalendarProvider provider =\n            LocaleProviderAdapter.getAdapter(CalendarProvider.class, aLocale)\n                                 .getCalendarProvider();\n        if (provider != null) {\n            try {\n                return provider.getInstance(zone, aLocale);\n            } catch (IllegalArgumentException iae) {\n                // fall back to the default instantiation\n            }\n        }\n\n        Calendar cal = null;\n\n        if (aLocale.hasExtensions()) {\n            String caltype = aLocale.getUnicodeLocaleType(\"ca\");\n            if (caltype != null) {\n                switch (caltype) {\n                case \"buddhist\":\n                cal = new BuddhistCalendar(zone, aLocale);\n                    break;\n                case \"japanese\":\n                    cal = new JapaneseImperialCalendar(zone, aLocale);\n                    break;\n                case \"gregory\":\n                    cal = new GregorianCalendar(zone, aLocale);\n                    break;\n                }\n            }\n        }\n        if (cal == null) {\n            // If no known calendar type is explicitly specified,\n            // perform the traditional way to create a Calendar:\n            // create a BuddhistCalendar for th_TH locale,\n            // a JapaneseImperialCalendar for ja_JP_JP locale, or\n            // a GregorianCalendar for any other locales.\n            // NOTE: The language, country and variant strings are interned.\n            if (aLocale.getLanguage() == \"th\" \u0026\u0026 aLocale.getCountry() == \"TH\") {\n                cal = new BuddhistCalendar(zone, aLocale);\n            } else if (aLocale.getVariant() == \"JP\" \u0026\u0026 aLocale.getLanguage() == \"ja\"\n                       \u0026\u0026 aLocale.getCountry() == \"JP\") {\n                cal = new JapaneseImperialCalendar(zone, aLocale);\n            } else {\n                cal = new GregorianCalendar(zone, aLocale);\n            }\n        }\n        return cal;\n    }\n\n}\n\n```\n\n## JapaneseImperialCalendar extends Calendar\n```java\nclass JapaneseImperialCalendar extends Calendar {\n\n}\n```\n## GregorianCalendar extends Calendar\n```java\npublic class GregorianCalendar extends Calendar {\n\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Ffactory-design-pattern","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femahtab%2Ffactory-design-pattern","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Ffactory-design-pattern/lists"}