liveBook · Manning

Modularity

As explained in Functional Design and Architecture: Examples in Haskell

Modularity is a structural property in which a program is divided into relatively independent parts with separable responsibilities.

Modularity divides a large program into relatively independent parts, grouping related behavioral meaning while keeping responsibilities separable. Packages, services, libraries, and subsystems provide common organizational forms. section 1.3.2 section 1.4.1

A useful module exposes a stable public interface while hiding an unstable private implementation. Clients depend on the interface rather than implementation details, so internal changes need not break them. section 1.4.1

Modularity works with several complementary design ideas:

  • Interfaces establish the boundary that client code uses. section 1.3.2
  • Inversion of control helps separate cooperating responsibilities. section 1.3.2 section 1.4.2
  • Polymorphism allows multiple implementations to vary behind a unifying interface. section 1.4.1
  • Low coupling and high cohesion keep complexity manageable across object-oriented, imperative, and functional designs. section 1.6

Opaque C interfaces

C can represent a module with a public opaque type and procedures such as create and destroy operations. Client code uses the declared interface without depending on the private structure behind it. section 1.4.1

                                                         #1
                                                         #2
typedef struct MYPROCOBJECT_Tag MYPROCOBJECT;            #3   
typedef struct MYPROCTYPE_Tag   MYPROCTYPE;
  
MYPROCOBJECT *visor_proc_CreateObject(MYPROCTYPE *type,  #4
                                      const char *name,
                                      void *context);
void          visor_proc_DestroyObject(MYPROCOBJECT *obj);

Inspect the opaque C declarations that separate public types and procedures from their implementation. section 1.4.1

How Functional Design and Architecture: Examples in Haskell covers it

How deep it goes
Defines decomposition, interface boundaries, and implementation hiding, but stops short of a detailed modularity procedure.
Examples
Uses C opaque types, Linux kernel-style procedures, sensor interfaces, and adapter-based object-oriented designs.
What it assumes
Assumes familiarity with programs and interfaces while introducing modularity across imperative, object-oriented, and functional paradigms.
What you can do after
Evaluate designs by identifying separable responsibilities, stable interfaces, hidden implementations, coupling, and cohesion.
How it connects
Connects modularity with interfaces, inversion of control, polymorphism, opaque data types, coupling, and cohesion.

Also explained in

Compare how 10 books explain modularity →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Design and Architecture: Examples in Haskell. The section links point to the parts of the book it draws on.