There's some hope to do it as one shape. You can adjust stroke dashes to the right lengths and places. It needs some tinkering and the result isn't easily forced to exact predetermined dimensions.
Another way to make it formally as one shape is to have a custom pattern brush. The pattern can be 2 rectangles. The result an have exact dimensions. In practice the shape of course is a combination and not easier to do than 2 or 3 separate shapes
Here's a screenshot of the pattern brush option version and the brush settings. Two colored rectangles are drawn and dragged simultaneously to the brushes collection:

Then a black circle has got a stroke which applies the new brush.
Dimensionally perfect result is got easily if you have 2 copies of your shape - one without stroke, only the fill and one without a fill, only the stroke.
Clip from the stroke the needed parts off with the scissors tool or hide them with a clipping or opacity mask as in your old example, The mask can be a group, if needed.
About Pathfinder: It can be used. You can expand the stroke-only version ie. transform the stroke to a filled path. Then you can with pathfinder panel subtract a shape from it or make an intersection. This is useless, if you absolutely for some reason need a single shape version.