Mathematical modeling and computer simulation have often helped to improve our understanding, prediction and decision-making in the face of epidemics. However, one problem that is often encountered when developing and implementing epidemiological models is the mixing of different aspects of the model. Indeed, epidemiological models become increasingly complex as new concerns are taken into account (age, gender, spatial heterogeneity, containment or vaccination policies, etc.). These aspects, which are generally intertwined, make models difficult to extend, modify or reuse. In mathematical modeling applied to epidemiology, two main approaches are considered. The first, that of "compartmental models", has proved robust and yields fairly good results for many diseases. However, it is difficult to take into account certain sources of heterogeneity. The second approach, based on "contact networks," has proved intuitive for representing contacts between individuals, and delivers very good results for epidemic prediction. However, this approach requires more effort to implement. A solution to this problem has been proposed: Kendrick. It's a modeling and simulation tool and approach that has shown promising results for separating epidemiological concerns, by defining them as stochastic automata (continuous-time Markov chain), which can then be combined using an associative and pseudo-commutative tensorial sum operator. However, a significant limitation of this approach is its restricted application to compartmental models. Given the peculiarities and shortcomings of each approach, in this research work we propose a combined approach between compartmental and contact network models. The aim is to generalize the Kendrick approach to take into account certain aspects of contact networks in order to improve the predictive quality of models with significant heterogeneity in contact structure, while retaining the simplicity of compartmental models. To achieve this, the extension of compartmental models is made possible by applying the infection force formalism of Bansal et al. (2007) and the behavioral Template Method Design Pattern. The result is an approach that is easy to define, analyze and simulate. We validated this approach on different techniques for generalizing compartmental models. Simulation results show that our approach successfully captures the following aspects of contact network models.