Let $\rightarrowtail$ denote a monomorphism.


Given a morphism $A \stackrel{j}{\to} B$, I am interested in the (not necessarily unique) existence of a factorization $A \stackrel{j'}{\rightarrowtail} X \stackrel{s}{\to} B$ of $j$ (so $j = s \circ j'$) such that for any other factorization $A \stackrel{i}{\rightarrowtail} Y \stackrel{t}{\to} B$ of $j$, there exists a morphism $Y \stackrel{t'}{\to} X$ with $j' = t' \circ i$ and $t = s \circ t'$. [A commutative diagram for the required morphisms](https://i.stack.imgur.com/a2hfI.png).


In $\mathbf{Set}$, such an $X$ can be obtained by constructing the coproduct $A + B$, and appropriately defining the morphisms. In $\mathbf{Graph}$ also a construction exists, by taking $A + B$ and enriching the graph with additional edges.


Intuitively, one can think of $B$ as a type object for $A$, and I am looking for an alternative type object $X$ that preserves subobject $A$, but in some sense does not lose instances $Y$ of $B$.


Are there related constructions in the literature? And what are sufficient conditions for such an $X$ to exist? Any pointers would be greatly appreciated.



Subobject- and factorization-preserving typings
One general way to construct such an $X$ is as a [partial map classifier](https://ncatlab.org/nlab/show/partial+map+classifier) for $j:A\to B$, regarded as an object of the slice category $\mathcal{E}/B$.


To see this, note first that if $s:X\to B$ is such a partial map classifier, then it comes with a canonical partial map $X\rightharpoonup A$ in $\mathcal{E}/B$, which means a span $X \overset{k}{\leftarrowtail} S \overset{g}{\to} A$ such that $s k = j g$. But the identity of $A$ is also a partial map to $A$ (which happens to be total), so by the universal property of $X$ there is a unique map $h:A\to X$ such that $h^\*(S)$ is all of $A$, which is to say that $h$ factors through $k$ by a map $h':A\to S$ such that $k h' = h$ and $g h' = 1\_A$. This implies that $h'$ is a monomorphism, hence so is $h$.


Now let $a,b:K \rightrightarrows S$ be the kernel pair of $g$. Then $k a$ and $k b$ are two maps $K\to X$ whose composite with $(k,g)$ is the same partial map $K\rightharpoonup A$ (in fact they are both the total map $g a = g b$). By the uniqueness aspect of the universal property of $X$, we have $ka=kb$, hence $a=b$ since $k$ is monic. Thus $g$ is also monic, and hence $h'$ and $g$ are isomorphisms. In other words, the canonical partial map $X\rightharpoonup A$ is of the form $X \overset{j'}{\leftarrowtail} A \overset{1\_A}{\to} A$, where $s j' = j$ as desired.


Now suppose given another factorization $A \overset{i}{\rightarrowtail} Y \overset{t}{\to} B$ with $i$ monic and $j = t i$. Then $Y \overset{i}{\leftarrowtail} A \overset{1\_A}{\to} A$ is a partial map $Y \rightharpoonup A$ in $\mathcal{E}/B$, so there is a unique $t' : Y\to X$ such that $s t' = t$ (meaning that $t'$ is a morphism in $\mathcal{E}/B$) and there is a pullback square $t' \circ i = j' \circ 1\_A$, which in particular implies $t' i = j'$. (In particular, although $s t'= t$ and $t' i= j'$ are not enough to characterize $t'$ uniquely, the extra assumption that $t' \circ i = j' \circ 1\_A$ is a pullback square does so characterize it.)


Since partial map classifiers exist in Boolean extensive categories and in toposes, a factorization such as you describe will exist in those two classes of categories.


