Save this video free

UNC COMP 301 - F26/Lec 12 - Adapter Design Pattern; Composition over Inheritance; Decorator DP

Muhammad Sayeed Ghani · 1:15:30 · Watch on YouTube

Part of UNC Chapel Hill COMP 301. See all 22 lectures and search them

These notes were made with YouTube Collector. Paste any YouTube link and get the same: a summary, chapters and a searchable transcript.

Overview

Muhammad Sayeed Ghani explains two structural design patterns and the design principle behind them: Adapter translates an incompatible API into the interface a client expects, while Decorator adds or modifies behavior through composition rather than a growing inheritance hierarchy. Media-player, dog, window, and price-tag examples show how delegation works, why feature combinations can cause class explosion, how decorators can be chained, and where Java’s I/O classes use the pattern.

Key takeaways

Chapters

0:00 Structural Patterns and the Adapter Pattern’s Purpose
3:00 Media Player Example: A Modern Target and Legacy APIs
5:30 Why an Adapter Is Safer Than Changing Client or Legacy Code
10:00 Implementing an Adapter with Encapsulation and Delegation
15:00 Separate Adapters for VLC and MP4 Players
22:00 Adapter Use Cases: Third-Party APIs and Payment Providers
28:00 Dog Features Reveal Inheritance Class Explosion
32:00 Runtime State-Based Composition for Dog Variations
35:00 Window Features Make Inheritance Combinations Unmanageable
41:00 Building a Window Decorator with Width Adjustments
49:00 Decorator UML, Interface Types, and Window Usage
56:00 Discounted Price Tags Modify Delegated Results
1:01:00 Chaining Decorators, Unwrapping, and Type Access
1:08:00 Extended Price-Tag Interfaces and Java I/O Decorators
1:12:00 Decorator Trade-Offs: Ordering, Compatibility, and Encapsulation

Keep these chapters and the full searchable transcript in your own library.

Transcript excerpt

0:00 In the last lecture, we started discussing the aspect of object-oriented programming which is referred to as composition over inheritance and that directly relates to the uh the the uh decorator design pattern. Um and before that uh I would like to discuss one other um structural design pattern which is the adapter design pattern which I mentioned in the last lecture and I'd like to squeeze that in first because uh the next assignment which should be coming out before our next lecture and Tuesday is a well-being day. So um that assignment is based on adaptive design pattern. So let's discuss that first and then we'll go ahead and come back to composition or

0:47 inheritance and continue on with the decorator design pattern. So let's discuss uh the adaptive design pattern. Now that is part of the structural design patterns. So, so far we've looked at um we started taking a look at iterator which was part of the behavioral design patterns and that relates to how um classes interrelate and how they communicate and how the responsibilities are divided among themselves. Creational patterns we looked at next and those relate to how you create new classes and objects and structural patterns are a little different and they relate to how you compose different classes and objects together to construct larger

1:35 structures. So now we're heading towards larger structures and we'll take a look at two design patterns today. the adapter design pattern and the decorator. So let's start off with the adapter design pattern. Now the adapter design pattern as is defined by the gang of four uh and I'll read this out to you uh converts the interface of a class into another interface that the client expects. The adapter lets classes work together that couldn't otherwise because

This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.

In this course

Related notes

Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Muhammad Sayeed Ghani.

Want the full transcript?

Save this video in YouTube Collector to get its complete searchable transcript, your own AI summaries, and a library that keeps every video you collect in one place.