Computer Science Fundamentals

Computer science fundamentals including system design, software development, web, security, database, OS, networking, etc

Member-only story

Mastering Design Patterns with Examples — Command Pattern

Larry | Peng Yang
Computer Science Fundamentals
9 min readApr 18, 2023

--

Photo by insung yoon on Unsplash

Overview

Welcome to another post on the design pattern series! In this chapter, we take encapsulation to a whole new level: we’re going to encapsulate method invocation.

The Command Design Pattern is a powerful behavioral pattern that allows developers to encapsulate a request or action as an object, thereby promoting loose coupling and greater control over the request’s lifecycle. This pattern is widely used in software development to decouple the object that initiates the request from the object that actually performs the action. This article explores the Command Pattern using a practical example from the popular book “Head First Design Patterns”.

Use command pattern in Remote Control problem

Let’s take a look at the Remote Control example in the Head First Design Pattern book.

Understand the requirement

remote control, credit: head first design patterns

The remote control features seven programmable slots (each can be assigned to a different household device) along…

--

--

Computer Science Fundamentals
Computer Science Fundamentals

Published in Computer Science Fundamentals

Computer science fundamentals including system design, software development, web, security, database, OS, networking, etc

Larry | Peng Yang
Larry | Peng Yang

Written by Larry | Peng Yang

Software Engineer in Tokyo. Aim to understand computer science very well. www.buymeacoffee.com/yangpeng. www.linkedin.com/in/yangpeng-tech.

No responses yet