r/PHPhelp • • Jul 08 '21

What is a subsystem in PHP?

I've been learning about OOP and design patterns in PHP, and hear this subsystem word used when describing facades, for example.

A facade provides a simple interface for a complex subsystem.

Source

It later goes on to say...

The Complex Subsystem consists of dozens of various objects. To make them all do something meaningful, you have to dive deep into the subsystem’s implementation details, such as initializing objects in the correct order and supplying them with data in the proper format.

Subsystem classes aren’t aware of the facade’s existence. They operate within the system and work with each other directly.

But I'm not really sure if I understand what a subsystem is.

Can someone ELI5, perhaps?

Thanks.

8 Upvotes

6 comments sorted by

8

u/[deleted] Jul 08 '21

Subsystem is another word for component, package or module.

Over time, each of these terms gets overloaded with meanings. For example, package could imply that it's a Composer dependency but that's not necessarily true. So somebody uses a different term that doesn't carry the same baggage. But they're still referring to the same thing - a collection of functions and classes that work together privately to offer functionality exposed through a public interface.

0

u/[deleted] Jul 08 '21

I googled that sentence and found this in less than a minute:

[... a sub system] consists of dozens of various objects. To make them all do something meaningful, you have to dive deep into the subsystem’s implementation details, such as initializing objects in the correct order and supplying them with data in the proper format.

Subsystem classes aren’t aware of the facade’s existence. They operate within the system and work with each other directly.

Instead of making your code work with dozens of the framework classes directly, you create a facade class which encapsulates that functionality and hides it from the rest of the code. This structure also helps you to minimize the effort of upgrading to future versions of the framework or replacing it with another one.

The graphics associated with the explanation help:

https://refactoring.guru/design-patterns/facade#structure

1

u/[deleted] Jul 08 '21

Ok, thanks. A sub system consists of dozens of various objects, but what is a subsystem?

2

u/LiamTailor Jul 08 '21

I think it's just a name for a group of classes that are a part of the same task. Like a "password reset subsystem".

2

u/[deleted] Jul 08 '21

Ah, ok. This makes more sense, thanks.

2

u/[deleted] Jul 08 '21

Its just a phrase to encompass a group of classes. So in this example, the susbsystem would be the classes in the bottom cloud that talk to each other directly to convert a video:

class VideoFile
// ...
class OggCompressionCodec 
// ... 
class MPEG4CompressionCodec 
// ... 
class CodecFactory 
// ... 
class BitrateReader // ... 
class AudioMixer 

The facade would be a single class that makes all that accessible:

class VideoConverter 
function convert(filename, format)
//..

The examples in the original link are in PHP, but if you read through that section as pseudo code, its all laid out pretty well.