Compartmentalization is an unconscious psychological defense mechanism used to avoid cognitive dissonance, or the mental discomfort and anxiety caused by a person's having conflicting values, cognitions, emotions, beliefs, etc. within themselves.
Compartmentalization allows these conflicting ideas to co-exist by inhibiting direct or explicit acknowledgement and interaction between separate compartmentalized self states.
Psychoanalytic views 
Psychoanalysis considers that whereas isolation separates thoughts from feeling, compartmentalization separates different (incompatible) cognitions from each other. As a secondary, intellectual defense, it may be linked to rationalization. Related also is the phenomenon of neurotic typing, whereby everything must be classified into mutually exclusive and watertight categories.
Those suffering from borderline personality disorder will often divide people into all good versus all bad, to avoid the conflicts removing the compartments would inevitably bring, using denial or indifference to protect against any indications of contradictory evidence.
Using indifference towards a better viewpoint is a normal and common example of this. It can be caused by someone having used multiple compartment ideals and having been uncomfortable with modifying them, at risk of being found incorrect. This often causes double-standards, and bias.
Social identity 
Conflicting social identities may be dealt with by compartmentalizing them and dealing with each only in a context-dependent way.
Literary examples 
Graham Greene has one of his corrupt officials use the rectangular boxes of Ben Nicholson's art as a guide to avoiding moral responsibility for bureaucratic decision-making - a way to compartmentalize oneself within one's own separately coloured box.
Doris Lessing considered that the essential theme of The Golden Notebook was "that we must not divide things off, must not compartmentalise. 'Bound. Free. Good. Bad. Yes. No. Capitalism. Socialism. Sex. Love...'".
See also 
- Tangney. In Leary, Mark R. Leary and Price, June. Handbook of self and identity. Guilford Press. pp. 58–61. ISBN 978-1-4625-0305-6.
- Nancy McWilliams, Psychoanalytic Diagnosis (2011) p. 135-6
- McWilliams, p. 200 and p. 136
- Otto Fenichel, The Psychoanalytic Theory of Neurosis (1946) p. 286
- Salman Akhtar, Comprehensive Dictionary of Psychoanalysis (2009) p. 42
- J. W. Reich et al, Handbook of Adult Resilience (2012) p. 192
- Gabbard, Glen O. (2010). Long-Term Psychodynamic Psychotherapy. London. pp. 34–39. ISBN 978-1-58562-144-6.
- R. J. Crisp, The Psychology of Social and Cultural Diversity (2011) p. 16 and p. 39
- Graham Greene, The Human Factor (1978) p. 38
- Doris Lessing, The Golden Notebook (1973) p. 10