01-01-01 Factory Design Pattern

Pattern Name

Synopsis:

Factory pattern is one of most used design pattern in Java. This type of design pattern comes under creational pattern as this pattern provides one of the best ways to create an object.

Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.
Varying: subclass of object that is instantiated.

I would like to think about design patterns in terms of classes being as ‘people,’ and patterns are ways that people talk to each other.

So, to me the factory pattern is like a hiring agency. You’ve got someone that will need a variable number of workers. This person may know some info they need in the people they hire, but that’s it.

So, when they need a new employee, they call the hiring agency and tell them what they need. Now, to actually hire someone, you need to know a lot of stuff - benefits, eligibility verification, etc. But the person hiring doesn’t need to know any of this - the hiring agency handles all of that.

In the same way, using a Factory allows the consumer to create new objects without having to know the details of how they’re created, or what their dependencies are - they only have to give the information they actually want.

Intent:

In what situations can the pattern be used, we can consider it as pattern`s context.

  1. creates objects without exposing the instantiation logic to the
    client
  2. refers to the newly created object through a common interface

Structure

Diagram using the Object Modeling Technique (OMT)
这里写图片描述

Implementation

: Implementation details to consider

Applicability

Participants

Classes and objects in design

: A list of related patterns

Motivation

: A scenario that illustrates the problem

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值