{"id":21735874,"url":"https://github.com/izzyluuuuh/factory-method-pattern","last_synced_at":"2025-03-21T00:26:03.444Z","repository":{"id":223994683,"uuid":"762105700","full_name":"izzyluuuuh/factory-method-pattern","owner":"izzyluuuuh","description":"Implementation of Factory Method Pattern Using Java","archived":false,"fork":false,"pushed_at":"2024-02-25T02:47:56.000Z","size":237,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-25T21:09:30.198Z","etag":null,"topics":["application-development","factory-method-pattern","java"],"latest_commit_sha":null,"homepage":"","language":"Java","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/izzyluuuuh.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}},"created_at":"2024-02-23T05:07:00.000Z","updated_at":"2024-02-24T01:51:18.000Z","dependencies_parsed_at":"2024-02-23T06:42:35.778Z","dependency_job_id":null,"html_url":"https://github.com/izzyluuuuh/factory-method-pattern","commit_stats":null,"previous_names":["izzyluuuuh/factory-method-pattern"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzyluuuuh%2Ffactory-method-pattern","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzyluuuuh%2Ffactory-method-pattern/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzyluuuuh%2Ffactory-method-pattern/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzyluuuuh%2Ffactory-method-pattern/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/izzyluuuuh","download_url":"https://codeload.github.com/izzyluuuuh/factory-method-pattern/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244713983,"owners_count":20497751,"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":["application-development","factory-method-pattern","java"],"created_at":"2024-11-26T05:15:20.759Z","updated_at":"2025-03-21T00:26:03.415Z","avatar_url":"https://github.com/izzyluuuuh.png","language":"Java","readme":"# Factory Method Pattern\n## Implementation of Factory Method Pattern Using Java\n\nThe **Factory Method pattern** defines an interface or abstract class for creating objects in a superclass but allows subclasses to alter the type of objects to be created.\n\n### Project Name: *TestFactory*\n\n1. Create an abstract superclass named **Laptop**. Any subclass of an abstract class must either implement all of the abstract methods in the superclass or be declared abstract itself. Copy the code below.\n ```java\nabstract class Laptop {\n\n  public abstract int getRAM();\n  public abstract int getSSD();\n  public abstract String getCPU();\n\n  public String toString() {\n    return \"RAM=\"+this.getRAM()+\"GB, SSD=\"+this.getSSD()+\", CPU=\"+this.getCPU();\n  }\n}\n```\n2. Create a subclass named **Minimum** that extends your superclass. In this class, declare three (3) private variables with the following names and data types:\n- **ram** (int)\n- **ssd** (int)\n- **cpu** (String)\n3. Copy the code below for the constructor of your **Minimum** class. This constructor has three (3) parameters: **ram**, **ssd**, and **cpu**. Parameters are separated by commas as seen below.\n```java\npublic Minimum(int ram, int ssd, String cpu){\n  this.ram=ram;\n  this.ssd=ssd;\n  this.cpu=cpu;\n}\n```\n4. Create three (3) public getter methods named after the abstract methods in your superclass. These methods should return the value of the instance variables. Ex. **return this.ram;**\n5. Add another subclass named **Recommended** that also extends the same superclass. This class shall have the same content with your **Minimum** class.\n6. Add a class named **LaptopFactory**. Copy the code below for its method.\n```java\npublic static Laptop getSpecs(String type, int ram, int ssd, String cpu){\n  if(\"min\".equalsIgnoreCase(type))\n    return new Minimum(ram, ssd, cpu);\n  else if(\"reco\".equalsIgnoreCase(type))\n    return new Recommended(ram, ssd, cpu);\n  return null;\n}\n```\n7. Use the public class named **TestFactory** to execute your Factory Method pattern implementation. In its main method, instantiate a **Laptop** object named **min**. Copy the code below.\n```java\nLaptop min = LaptopFactory.getSpecs(\"min\", 8, 256, \"i5-12450Hz\");\n```\n8. Instantiate another **Laptop** object named **reco**. Follow the syntax above but use the following values for the 2nd to 4th parameter: **16, 512, i7-12700Hz**\n9. Display the content of the two (2) objects in separate lines. \n\n**Sample Output:**\n```java\nMinimum Specs:\nRAM=8GB, SSD=256, CPU=i5-12450Hz\nRecommended Specs:\nRAM=16GB, SSD=512, CPU=i7-12700Hz\n```\n\n🖥️ Just a Laboratory Exercise for my 3rd-year college course \"Application Development and Emerging Technologies.\"\n\u003e SY2324-1T\n\n💻 Use NetBeans 🖱️\n\n💙 Instagram: [@izzyluuuuh](https://www.instagram.com/izzyluuuuh/)\n\n## Actual Output\n![preview img](https://github.com/izzyluuuuh/factory-method-pattern/blob/main/testfactory-output.png)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizzyluuuuh%2Ffactory-method-pattern","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fizzyluuuuh%2Ffactory-method-pattern","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizzyluuuuh%2Ffactory-method-pattern/lists"}