Design Mode DP (3) Abstract Factory features: The system is independent of the creation, combination, and use of product classes to provide corresponding interfaces for external users, instead of implementing a class system, one of the products of multiple different systems is configured to consider the enhancement of the relevance between different product classes to the factory method (different factories create instances of different products) code: ## top-level abstract factory class, create Abstract public interface imo-actfactory {ICat createCat (); IDog createDog ();} # The following defines two specific animal factories (BlackAnimalFactory and WhiteAnimalFactory) public class BlackAnimalFactory implements imo-actfactory {public ICat createCat () {return new BlackCat ();} public IDog createDog () {return n Ew BlackDog () ;}} public class WhiteAnimalFactory implements imo-actfactory {public ICat createCat () {return new WhiteCat ();} public IDog createDog () {return new WhiteDog ();}} # define the product interface. Here is the cat and dog interface public interface ICat {void eat ();} public interface IDog {void eat ();} ### define the specific implementation of product class interfaces in different forms (black and white). Here is the Black Cat, Black Dog and white Cat, white dog public class BlackCat implements Cat {public eat () {System. out. println ("the black cat is eat Ting !! ") ;}} Public class BlackDog implements Dog {public eat () {System. out. println (" the black dog is eatting !! ") ;}} Public class WhiteCat implements Cat {public eat () {System. out. println (" the white cat is eatting !! ") ;}} Public class WhiteDog implements Dog {public eat () {System. out. println (" the white dog is eatting !! ") ;}} Call: public static void main (String arg []) {IFactory if1 = new BlackAnimalFactory (); ICat ic1 = if1.createCat (); ic1.eat (); IDog id1 = if1.createDog (); id1.eat (); IFactory if2 = new WhiteAnimalFactory (); ICat ic2 = if2.createCat (); ic2.eat (); IDog id2 = if2.createDog (); id2.eat ();} result: the black cat is eatting !! The black dog is eatting !! The white cat is eatting !! The white dog is eatting !!