A simple paradigm for graph recognition: application to cographs and distance hereditary graphs