Throughout the software life cycle, most of the developed software systems need to be modified for accommodating some requirements change. This kind of maintenance activities requires much effort, in the sense that the program modules expensively certified through robust verification and testing activities must be certified again against several modifications, and the activities continue to occur until its retirement. To address this problem, we propose a systematic and safe approach to identifying design structure for applying design patterns in order to reduce further maintenance costs. The design patterns provide a high degree of design flexibility for accidental requirements changes. Our approach automatically identifies design spots to which the design patterns can be applied, then on which the predefined transformation rule would be applied. We define the formal model of representing an object-oriented program as 8-tuple. Based on the formal model, a set of predicates is defined to capture the structural and behavioral design properties of a program via Prolog-like logic predicates. For a certain design pattern, we develop an inference rule for identifying potential design spots to which the design pattern can be applied, and an algorithm describing how to apply a sequence of refactoring operations for transforming each candidate spot into the representation of the desired design pattern.