精华内容
下载资源
问答
  • Design Pattern - Factory Method(C#)

    万次阅读 多人点赞 2019-02-02 17:09:35
    分享一个大牛的人工智能教程。零基础!通俗易懂!风趣幽默!希望你也加入到人工智能的队伍中来!... Definition Define an interface for creating an object, but let sub classes decide which ... Factory Metho...

    分享一个大牛的人工智能教程。零基础!通俗易懂!风趣幽默!希望你也加入到人工智能的队伍中来!请点击http://www.captainbed.net 

    Definition

    Define an interface for creating an object, but let sub classes decide which class to instantiate. Factory Method lets a class defer instantiation to sub classes.

    Participants

        The classes and/or objects participating in this pattern are:

    • Product (Page)
      • Defines the interface of objects the factory method creates
    • ConcreteProduct (SkillsPage, EducationPage, ExperiencePage)
      • Implements the Product interface
    • Creator (Document)
      • Declares the factory method, which returns an object of type Product. Creator may also define a default implementation of the factory method that returns a default ConcreteProduct object.
      • May call the factory method to create a Product object.
    • ConcreteCreator (Report, Resume)
      • Overrides the factory method to return an instance of a ConcreteProduct.

    Sample Code in C#


    This structual code demonstrates the Factory Method offering great flexibility in creating different objects. The abstract class may provide a default object, but each subclass can instantiate an extended version of the object.

    /*
     * Structural Factory Method Design Pattern.
     */
    
    namespace FactoryMethod.Sample
    {
        using System;
        using System.Linq;
    
        /// <summary>
        /// Startup class for Structural Factory Method Design Pattern.
        /// </summary>
        internal static class Program
        {
            #region Methods
    
            /// <summary>
            /// Entry point into console application.
            /// </summary>
            private static void Main()
            {
                // An array of creators.
                var creators = new Creator[2];
                creators[0] = new ConcreteCreatorA();
                creators[1] = new ConcreteCreatorB();
    
                // Iterate over creators and create products.
                foreach (Product product in creators.Select(creator => creator.FactoryMethod()))
                {
                    Console.WriteLine("Created {0}", product.GetType().Name);
                }
            }
    
            #endregion
        }
    
        /// <summary>
        /// The 'Product' abstract class.
        /// </summary>
        internal abstract class Product
        {
        }
    
        /// <summary>
        /// A 'ConcreteProduct' class.
        /// </summary>
        internal class ConcreteProductA : Product
        {
        }
    
        /// <summary>
        /// A 'ConcreteProduct' class.
        /// </summary>
        internal class ConcreteProductB : Product
        {
        }
    
        /// <summary>
        /// The 'Creator' abstract class
        /// </summary>
        internal abstract class Creator
        {
            #region Public Methods and Operators
    
            /// <summary>
            /// The factory method.
            /// </summary>
            /// <returns>
            /// The <see cref="Product"/>.
            /// </returns>
            public abstract Product FactoryMethod();
    
            #endregion
        }
    
        /// <summary>
        /// A 'ConcreteCreator' class.
        /// </summary>
        internal class ConcreteCreatorA : Creator
        {
            #region Public Methods and Operators
    
            /// <summary>
            /// The factory method.
            /// </summary>
            /// <returns>
            /// The <see cref="Product"/>.
            /// </returns>
            public override Product FactoryMethod()
            {
                return new ConcreteProductA();
            }
    
            #endregion
        }
    
        /// <summary>
        /// A 'ConcreteCreator' class.
        /// </summary>
        internal class ConcreteCreatorB : Creator
        {
            #region Public Methods and Operators
    
            /// <summary>
            /// The factory method.
            /// </summary>
            /// <returns>
            /// The <see cref="Product"/>.
            /// </returns>
            public override Product FactoryMethod()
            {
                return new ConcreteProductB();
            }
    
            #endregion
        }
    }
    
    // Output:
    /*
    Created ConcreteProductA
    Created ConcreteProductB
    
    */

    This real-world code demonstrates the Factory Method offering flexibility in creating different documents. The derived Document classes Report and Resume instantiate extended versions of the Document class. Here, the Factory Method is called in the constructor of the Document base class.

    /*
     * Real-World Factory Method Design Pattern.
     */
    
    namespace FactoryMethod.RealWorld
    {
        using System;
        using System.Collections.Generic;
    
        /// <summary>
        /// Startup class for Real-World Factory Method Design Pattern.
        /// </summary>
        internal static class Program
        {
            #region Methods
    
            /// <summary>
            /// Entry point into console application.
            /// </summary>
            private static void Main()
            {
                // Note: constructors call Factory Method.
                var documents = new Document[2];
                documents[0] = new Resume();
                documents[1] = new Report();
    
                // Display document pages.
                foreach (Document document in documents)
                {
                    Console.WriteLine("\n" + document.GetType().Name + "--");
                    foreach (Page page in document.Pages)
                    {
                        Console.WriteLine(" " + page.GetType().Name);
                    }
                }
            }
    
            #endregion
        }
    
        /// <summary>
        /// The 'Product' abstract class.
        /// </summary>
        internal abstract class Page
        {
        }
    
        /// <summary>
        /// A 'ConcreteProduct' class.
        /// </summary>
        internal class SkillsPage : Page
        {
        }
    
        /// <summary>
        /// A 'ConcreteProduct' class.
        /// </summary>
        internal class EducationPage : Page
        {
        }
    
        /// <summary>
        /// A 'ConcreteProduct' class.
        /// </summary>
        internal class ExperiencePage : Page
        {
        }
    
        /// <summary>
        /// A 'ConcreteProduct' class.
        /// </summary>
        internal class IntroductionPage : Page
        {
        }
    
        /// <summary>
        /// A 'ConcreteProduct' class.
        /// </summary>
        internal class ResultsPage : Page
        {
        }
    
        /// <summary>
        /// A 'ConcreteProduct' class.
        /// </summary>
        internal class ConclusionPage : Page
        {
        }
    
        /// <summary>
        /// A 'ConcreteProduct' class.
        /// </summary>
        internal class SummaryPage : Page
        {
        }
    
        /// <summary>
        /// A 'ConcreteProduct' class.
        /// </summary>
        internal class BibliographyPage : Page
        {
        }
    
        /// <summary>
        /// The 'Creator' abstract class.
        /// </summary>
        internal abstract class Document
        {
            #region Constructors and Destructors
    
            /// <summary>
            /// Initializes a new instance of the <see cref="Document"/> class.
            /// </summary>
            protected Document()
            {
                CreatePages();
            }
    
            #endregion
    
            #region Public Properties
    
            /// <summary>
            /// Gets the pages.
            /// </summary>
            public List<Page> Pages { get; } = new List<Page>();
    
            #endregion
    
            // Factory Method
            #region Public Methods and Operators
    
            /// <summary>
            /// Create pages.
            /// </summary>
            protected abstract void CreatePages();
    
            #endregion
        }
    
        /// <summary>
        /// A 'ConcreteCreator' class.
        /// </summary>
        internal class Resume : Document
        {
            #region Public Methods and Operators
    
            /// <summary>
            /// Create pages.
            /// </summary>
            protected override void CreatePages()
            {
                Pages.Add(new SkillsPage());
                Pages.Add(new EducationPage());
                Pages.Add(new ExperiencePage());
            }
    
            #endregion
        }
    
        /// <summary>
        /// A 'ConcreteCreator' class.
        /// </summary>
        internal class Report : Document
        {
            #region Public Methods and Operators
    
            /// <summary>
            /// Create pages.
            /// </summary>
            protected override void CreatePages()
            {
                Pages.Add(new IntroductionPage());
                Pages.Add(new ResultsPage());
                Pages.Add(new ConclusionPage());
                Pages.Add(new SummaryPage());
                Pages.Add(new BibliographyPage());
            }
    
            #endregion
        }
    }
    
    // Output:
    /*
    
    Resume--
     SkillsPage
     EducationPage
     ExperiencePage
    
    Report--
     IntroductionPage
     ResultsPage
     ConclusionPage
     SummaryPage
     BibliographyPage
    
    */

     

    展开全文
  • org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionInterceptor' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve ...
  • Design Pattern - Abstract Factory(C#)

    万次阅读 多人点赞 2019-02-02 15:16:02
    AbstractFactory factory1 = new ConcreteFactory1(); var client1 = new Client(factory1); client1.Run(); // Abstract factory #2. AbstractFactory factory2 = new ConcreteFactory2(); var client2 = ...

    分享一个大牛的人工智能教程。零基础!通俗易懂!风趣幽默!希望你也加入到人工智能的队伍中来!请点击http://www.captainbed.net 

    Definition

    Provide an interface for creating families of related or dependent objects without specifying their concrete classes.

    Participants

    The classes and/or objects participating in this pattern are:

    • AbstractFactory (ContinentFactory)
      • Declares an interface for operations that create abstract products
    • ConcreteFactory (AfricaFactory, AmericaFactory)
      • Implements the operations to create concrete product objects
    • AbstractProduct (Herbivore, Carnivore)
      • Declares an interface for a type of product object
    • Product (Wildebeest, Lion, Bison, Wolf)
      • Defines a product object to be created by the corresponding concrete factory
      • Implements the AbstractProduct interface
    • Client (AnimalWorld)
      • Uses interfaces declared by AbstractFactory and AbstractProduct classes

    Sample Code in C#


    This structural code demonstrates the Abstract Factory pattern creating parallel hierarchies of objects. Object creation has been abstracted and there is no need for hard-coded class names in the client code.

    /*
     * Structural Abstract Factory Design Pattern.
     */
    
    namespace AbstractFactory.Sample
    {
        using System;
    
        /// <summary>
        /// Startup class for Structural Abstract Factory Design Pattern.
        /// </summary>
        internal static class Program
        {
            #region Public Methods and Operators
    
            /// <summary>
            /// Entry point into console application.
            /// </summary>
            public static void Main()
            {
                // Abstract factory #1.
                AbstractFactory factory1 = new ConcreteFactory1();
                var client1 = new Client(factory1);
                client1.Run();
    
                // Abstract factory #2.
                AbstractFactory factory2 = new ConcreteFactory2();
                var client2 = new Client(factory2);
                client2.Run();
            }
    
            #endregion
        }
    
        /// <summary>
        /// The 'AbstractFactory' abstract class.
        /// </summary>
        internal abstract class AbstractFactory
        {
            #region Public Methods and Operators
    
            /// <summary>
            /// Create product a.
            /// </summary>
            /// <returns>
            /// The <see cref="AbstractProductA"/>.
            /// </returns>
            public abstract AbstractProductA CreateProductA();
    
            /// <summary>
            /// Create product b.
            /// </summary>
            /// <returns>
            /// The <see cref="AbstractProductB"/>.
            /// </returns>
            public abstract AbstractProductB CreateProductB();
    
            #endregion
        }
    
        /// <summary>
        /// The 'ConcreteFactory1' class
        /// </summary>
        internal class ConcreteFactory1 : AbstractFactory
        {
            #region Public Methods and Operators
    
            /// <summary>
            /// Create product a.
            /// </summary>
            /// <returns>
            /// The <see cref="AbstractProductA"/>.
            /// </returns>
            public override AbstractProductA CreateProductA()
            {
                return new ProductA1();
            }
    
            /// <summary>
            /// Create product b.
            /// </summary>
            /// <returns>
            /// The <see cref="AbstractProductB"/>.
            /// </returns>
            public override AbstractProductB CreateProductB()
            {
                return new ProductB1();
            }
    
            #endregion
        }
    
        /// <summary>
        /// The 'ConcreteFactory2' class
        /// </summary>
        internal class ConcreteFactory2 : AbstractFactory
        {
            #region Public Methods and Operators
    
            /// <summary>
            /// Create product a.
            /// </summary>
            /// <returns>
            /// The <see cref="AbstractProductA"/>.
            /// </returns>
            public override AbstractProductA CreateProductA()
            {
                return new ProductA2();
            }
    
            /// <summary>
            /// Create product b.
            /// </summary>
            /// <returns>
            /// The <see cref="AbstractProductB"/>.
            /// </returns>
            public override AbstractProductB CreateProductB()
            {
                return new ProductB2();
            }
    
            #endregion
        }
    
        /// <summary>
        /// The 'AbstractProductA' abstract class.
        /// </summary>
        internal abstract class AbstractProductA
        {
        }
    
        /// <summary>
        /// The 'AbstractProductB' abstract class.
        /// </summary>
        internal abstract class AbstractProductB
        {
            #region Public Methods and Operators
    
            /// <summary>
            /// Interact.
            /// </summary>
            /// <param name="a">
            /// The abstract product a.
            /// </param>
            public abstract void Interact(AbstractProductA a);
    
            #endregion
        }
    
        /// <summary>
        /// The 'ProductA1' class.
        /// </summary>
        internal class ProductA1 : AbstractProductA
        {
        }
    
        /// <summary>
        /// The 'ProductB1' class.
        /// </summary>
        internal class ProductB1 : AbstractProductB
        {
            #region Public Methods and Operators
    
            /// <summary>
            /// Interact.
            /// </summary>
            /// <param name="a">
            /// The abstract product a.
            /// </param>
            public override void Interact(AbstractProductA a)
            {
                Console.WriteLine(GetType().Name + " interacts with " + a.GetType().Name);
            }
    
            #endregion
        }
    
        /// <summary>
        /// The 'ProductA2' class.
        /// </summary>
        internal class ProductA2 : AbstractProductA
        {
        }
    
        /// <summary>
        /// The 'ProductB2' class.
        /// </summary>
        internal class ProductB2 : AbstractProductB
        {
            #region Public Methods and Operators
    
            /// <summary>
            /// Interact.
            /// </summary>
            /// <param name="a">
            /// The abstract product a.
            /// </param>
            public override void Interact(AbstractProductA a)
            {
                Console.WriteLine(GetType().Name + " interacts with " + a.GetType().Name);
            }
    
            #endregion
        }
    
        /// <summary>
        /// The 'Client' class.
        /// Interaction environment for the products.
        /// </summary>
        internal class Client
        {
            #region Fields
    
            /// <summary>
            /// The abstract product a.
            /// </summary>
            private readonly AbstractProductA _abstractProductA;
    
            /// <summary>
            /// The abstract product b.
            /// </summary>
            private readonly AbstractProductB _abstractProductB;
    
            #endregion
    
            #region Constructors and Destructors
    
            /// <summary>
            /// Initializes a new instance of the <see cref="Client"/> class.
            /// </summary>
            /// <param name="factory">
            /// The abstract factory.
            /// </param>
            public Client(AbstractFactory factory)
            {
                _abstractProductA = factory.CreateProductA();
                _abstractProductB = factory.CreateProductB();
            }
    
            #endregion
    
            #region Public Methods and Operators
    
            /// <summary>
            /// Run.
            /// </summary>
            public void Run()
            {
                _abstractProductB.Interact(_abstractProductA);
            }
    
            #endregion
        }
    }
    
    // Output:
    /*
    ProductB1 interacts with ProductA1
    ProductB2 interacts with ProductA2
    
    */

    This real-world code demonstrates the creation of different animal worlds for a computer game using different factories. Although the animals created by the Continent factories are different, the interactions among the animals remain the same.

    /*
     * Real-World Abstract Factory Design Pattern.
     */
    
    namespace AbstractFactory.RealWorld
    {
        using System;
    
        /// <summary>
        /// Startup class for Real-World Abstract Factory Design Pattern.
        /// </summary>
        internal static class Program
        {
            #region Public Methods and Operators
    
            /// <summary>
            /// Entry point into console application.
            /// </summary>
            public static void Main()
            {
                // Create and run the African animal world.
                ContinentFactory africa = new AfricaFactory();
                var world = new AnimalWorld(africa);
                world.RunFoodChain();
    
                // Create and run the American animal world.
                ContinentFactory america = new AmericaFactory();
                world = new AnimalWorld(america);
                world.RunFoodChain();
            }
    
            #endregion
        }
    
        /// <summary>
        /// The 'AbstractFactory' abstract class.
        /// </summary>
        internal abstract class ContinentFactory
        {
            #region Public Methods and Operators
    
            /// <summary>
            /// Create carnivore.
            /// </summary>
            /// <returns>
            /// The <see cref="Carnivore"/>.
            /// </returns>
            public abstract Carnivore CreateCarnivore();
    
            /// <summary>
            /// Create herbivore.
            /// </summary>
            /// <returns>
            /// The <see cref="Herbivore"/>.
            /// </returns>
            public abstract Herbivore CreateHerbivore();
    
            #endregion
        }
    
        /// <summary>
        /// The 'ConcreteFactory1' class.
        /// </summary>
        internal class AfricaFactory : ContinentFactory
        {
            #region Public Methods and Operators
    
            /// <summary>
            /// Create carnivore.
            /// </summary>
            /// <returns>
            /// The <see cref="Carnivore"/>.
            /// </returns>
            public override Carnivore CreateCarnivore()
            {
                return new Lion();
            }
    
            /// <summary>
            /// Create herbivore.
            /// </summary>
            /// <returns>
            /// The <see cref="Herbivore"/>.
            /// </returns>
            public override Herbivore CreateHerbivore()
            {
                return new Wildebeest();
            }
    
            #endregion
        }
    
        /// <summary>
        /// The 'ConcreteFactory2' class.
        /// </summary>
        internal class AmericaFactory : ContinentFactory
        {
            #region Public Methods and Operators
    
            /// <summary>
            /// Create carnivore.
            /// </summary>
            /// <returns>
            /// The <see cref="Carnivore"/>.
            /// </returns>
            public override Carnivore CreateCarnivore()
            {
                return new Wolf();
            }
    
            /// <summary>
            /// Create herbivore.
            /// </summary>
            /// <returns>
            /// The <see cref="Herbivore"/>.
            /// </returns>
            public override Herbivore CreateHerbivore()
            {
                return new Bison();
            }
    
            #endregion
        }
    
        /// <summary>
        /// The 'AbstractProductA' abstract class.
        /// </summary>
        internal abstract class Herbivore
        {
        }
    
        /// <summary>
        /// The 'AbstractProductB' abstract class.
        /// </summary>
        internal abstract class Carnivore
        {
            #region Public Methods and Operators
    
            /// <summary>
            /// Eat.
            /// </summary>
            /// <param name="h">
            /// The herbivore.
            /// </param>
            public abstract void Eat(Herbivore h);
    
            #endregion
        }
    
        /// <summary>
        /// The 'ProductA1' class.
        /// </summary>
        internal class Wildebeest : Herbivore
        {
        }
    
        /// <summary>
        /// The 'ProductB1' class.
        /// </summary>
        internal class Lion : Carnivore
        {
            #region Public Methods and Operators
    
            /// <summary>
            /// Eat.
            /// </summary>
            /// <param name="h">
            /// The herbivore.
            /// </param>
            public override void Eat(Herbivore h)
            {
                // Eat Wildebeest.
                Console.WriteLine(GetType().Name + " eats " + h.GetType().Name);
            }
    
            #endregion
        }
    
        /// <summary>
        /// The 'ProductA2' class.
        /// </summary>
        internal class Bison : Herbivore
        {
        }
    
        /// <summary>
        /// The 'ProductB2' class.
        /// </summary>
        internal class Wolf : Carnivore
        {
            #region Public Methods and Operators
    
            /// <summary>
            /// Eat.
            /// </summary>
            /// <param name="h">
            /// The herbivore.
            /// </param>
            public override void Eat(Herbivore h)
            {
                // Eat Bison.
                Console.WriteLine(GetType().Name + " eats " + h.GetType().Name);
            }
    
            #endregion
        }
    
        /// <summary>
        /// The 'Client' class.
        /// </summary>
        internal class AnimalWorld
        {
            #region Fields
    
            /// <summary>
            /// The carnivore.
            /// </summary>
            private readonly Carnivore _carnivore;
    
            /// <summary>
            /// The herbivore.
            /// </summary>
            private readonly Herbivore _herbivore;
    
            #endregion
    
            // Constructor
    
            #region Constructors and Destructors
    
            /// <summary>
            /// Initializes a new instance of the <see cref="AnimalWorld"/> class.
            /// </summary>
            /// <param name="factory">
            /// The continent factory.
            /// </param>
            public AnimalWorld(ContinentFactory factory)
            {
                _carnivore = factory.CreateCarnivore();
                _herbivore = factory.CreateHerbivore();
            }
    
            #endregion
    
            #region Public Methods and Operators
    
            /// <summary>
            /// Run food chain.
            /// </summary>
            public void RunFoodChain()
            {
                _carnivore.Eat(_herbivore);
            }
    
            #endregion
        }
    }
    
    // Output:
    /*
    Lion eats Wildebeest
    Wolf eats Bison
    
    */

     

    展开全文
  • Factory Method vs Abstract Factory

    千次阅读 2016-12-20 16:26:46
    Factory Method vs Abstract Factory

    点开这篇着你已经大致对工厂方法有了一定的了解。但为什么依然对这两者的区别不是很明白,在搜索了一天、看了许多文章后我有了一点想法,在这里分享并记录一下。

    引用SO的一段文字:

    One difference between the two is that with the Abstract Factory pattern, a class delegates the responsibility of object instantiation to another object via composition whereas the Factory Method pattern uses inheritance and relies on a subclass to handle the desired object instantiation.

    这是说,Factory Method采用继承的方式,将创建产品推迟到子类;而Factory Abstract采用组合的方式,将一系列相关的产品组合到一起。

    其实抽象工厂中的每一个创建产品的接口都是一个工厂方法,只不过工厂方法创建一个产品,而抽象工厂创建一系列产品

    有个例子觉得非常简单又能说明问题:Shape。


    假设现在有Circle和Rectangle两种Shape,而Client代码需要根据情况创建一个具体的Shape。

    Factory Method:

    工厂方法由接口IShapeFactory中的CreateShape提供,方法创建一个Shape,但至于具体返回怎样的Shape,是由子类来完成的。对于CircleFactory,它实现工厂方法并返回一个Circle对象,RectangleFactory工厂则返回一个Rectangle对象。

    好了,现在Client代码想要一个Circle对象,则它不用自己出马,请具体的工厂来代工。

    IShapeFactory shapeFactory = new CircleFactory()//创建一个可以生产Circle的工厂
    Shape shape = shapeFactory.CreateShape();//Circle工厂负责创建一个Circle产品
    //Now, client could use this 'Circle' shape happily...
    

    现在,你希望创建一个带有颜色的Shape,比如RedCircle、GreenRectangle等等组合。在你手上有许多Shape,也买好了许多颜料,你希望工厂能够为你生产五颜六色的产品。依靠工厂模式的思想,将具体类的实例化与客户代码分离,由工厂负责生产具体的产品。

    RedCircle产品 = Circle产品 + Red产品

    每个工厂实际上要将有关系的产品组合在一起,为你创建出一个完整的产品。我想这就是为什么SO那段引用里说“抽象工厂模式利用组合”的原因吧。

    Abstract Factory:

    这张图看起来复杂,其实很简单不要慌张。

    与Factory Method不同的是,Abstract Factory只是能够生产一系列产品而已。它的做法无非是将相关的产品放在一起,由工厂一个个地来生产它们。你很聪明,其实抽象工厂里隐含着工厂方法的影子!一个个地CreateXXX其实就是工厂方法嘛。

    你想要一个绿色的矩形:

    IColorfulShapeFactory greenRectangleFactory = new GreenRectangleFactory();//请绿色矩形工厂来生产
    ColorfulShape colorfulShape = new ColorfulShape(greenRectangleFactory);//使用绿色矩形工厂生产的产品来实例化一个具体的GreenRectangle
    //Now, 你可以为所欲为了...
    

    与Factory Method略有不同的是,由于Abstract Factory生产一组产品,而你要的是一个完整的产品(它由这一组子产品构成),因此在ColorfulShape中,我们把工厂生产的产品用来初始化,这样就构成了一个完整的产品。


    Conclusion:

    1. Factory Method 生产一个产品;Abstract Factory 生产一组产品;

    2. 在 Factory Method 中,每一个CreateXXX方法实际上都是一个Factory Method ;

    3. 当需要扩展一个产品时,对于工厂方法来说只需要再实现一个生产这个产品的工厂就可以了,而对于抽象工厂来讲,因为最终的产品是由许多子产品组合而成的,因此就显得麻烦了多:

        还是以ColorfulShape产品为例。

      a. 改动发生在原子产品上,如增加一个蓝色,那只需要实现几个能够生产BlueShape的工厂;

      b. 改动发生在新子产品上,如你又想为ColorfulShape增加一个特性-----夹心材料(假设你在生产一款五颜六色、形状各异的夹心糖果,p.s.我实在想不来加什么属性好了。。),那就需要更改抽象工厂的接口,并牵连至所有实现了该接口的具体工厂!

        可以看到,不论如何改动都比Factory Method来的大。

    =====

    以上是个人的一些理解,希望在没有误导你的前提下,对你能够有些帮助。不妥之处还恳请指出。

    
    展开全文
  • 打开我自己建的temp文件夹,存的...idea关于找不到包的问题,比如:Java:程序包org.springframework.beans.factory.annotation不存在,像这样子 肿么办? 1、打开http://mvnrepository.com/search?q=org.apach

    打开我自己建的temp文件夹,存的乱七八糟的图片准备删删,发现之前想写博客的文章的图片还没写,像像酱样子
    这里写图片描述
    然后,写完就删图片
    idea关于找不到包的问题,比如:Java:程序包org.springframework.beans.factory.annotation不存在,像这样子
    这里写图片描述
    肿么办?
    1、打开http://mvnrepository.com/search?q=org.apache
    这里写图片描述
    2、然后大概搜索所需要的包,比如搜索:org.springframework.beans.factory.annotation(可能搜不到)
    那就,这个org.springframework.beans.factory(可能搜不到)
    那就,这个org.springframework.beans
    我记得这个可以搜到,反正大概这个意思
    这里写图片描述
    点击我画圈的红色部分
    3、然后跳转到
    这里写图片描述
    复制里面的内容到pom
    4、像这样
    这里写图片描述
    后下方有个import,点击就会自动导入所需要的包啦

    你是技术宅么?那就加入我们吧!点击下方链接 或 扫描二维码 即可。

    欢迎加入 CSDN技术交流群2:(点击即可加群)QQ群:456543087

               CSDN技术交流群(已满员):(点击即可加群)QQ群:681223095。  
    

    商务合作@群主,谢谢!

    [点击并拖拽以移动]

    展开全文
  • Design Patterns VI : Simple Factory, Factory Method, Abstract Factory
  • Factory模式

    千次阅读 2015-04-18 14:38:34
    工厂模式Factory Pattern
  • backdoor-factory详细使用教程

    万次阅读 2020-05-15 13:45:57
    backdoor-factory简介 backdoor-factory是一款后门构建工具。与其他工具不同的是,他不会增加软件的大小,而是利用代码缝隙进行注入,免杀效果更好。 backdoor-factory下载 kali预装的有坑,应该从github下载。 ...
  • PS Tray Factory

    2019-03-16 10:06:34
    The system tray icons management ...PS Tray Factory is a powerful and handy tool meant to flexibly control ALL the other icons in the system tray of the taskbar. PS Tray Factory will help you to...
  • Factory 模式

    千次阅读 2009-03-01 15:30:00
    解决实现依赖.[用Factory创建的对象,它的实现细节可能是不断变化的,但是它必须有一个稳定的接口]Factory模式 利用给Factory对象传递不同的参数,以返回具有相同基类或实现了同一接口的对象。Abstract Factory模式先...
  • ScheduleFactory

    2015-08-22 09:50:44
    * file name: ScheduleFactory.java * copyright: Unis Cloud Information Technology Co., Ltd. Copyright 2015, All rights reserved * description: * mofidy staff: zheng * mofidy time: 2015年8
  • Android 探究 LayoutInflater setFactory

    万次阅读 多人点赞 2016-05-26 08:32:37
    1、概述对于LayoutInflater setFactory,平时我们很少用到这个API,但是这个API我觉得还是有学习的必要的,能够很多意象不到的问题,准备围绕这方面编写一系列的文章。本篇包含: setFactory
  • org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'taskAction': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.B...
  • C++ Factory & AbstractFactory 模式

    千次阅读 2013-09-21 21:07:19
    1.工厂模式(Factory): Factory模式是为一类对象提供创建接口或延迟对象的创建到子类中实现 #include using namespace std; //抽象类 class Product { public: virtual ~Product() =0; protected: ...
  • 别人运行的时候,出现了这个异常,这个异常,我不知道我以前有没有遇到过...异常:org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘XXX’ 网上说,这个异常出现的原因...
  • Factory method 和 Abstract factory的区别

    千次阅读 2013-01-19 17:10:24
    Factory method: You have a factory that creates objects that derive from a particular base class 翻译:你有一个继承特定基类的派生类工厂,它能创建不同对象 Abstract factory: You have a factory that ...
  • Simple Factory

    千次阅读 2011-07-12 10:14:42
    工厂模式专门负责将大量有共同接口的类实例化。工厂模式可以动态决定将哪一个类实例化,...工厂模式有以下几种形态:简单工厂(Simple Factory)模式 工厂方法(Factory Method)模式 抽象工厂(Abstract Factory)模式
  • Dart factory 快速理解

    千次阅读 2019-10-17 10:47:20
    Factory constructors(工厂方法构造函数) 如果一个构造函数并不总是返回一个新的对象,则使用 factory 来定义 这个构造函数。例如,一个工厂构造函数 可能从缓存中获取一个实例并返回,或者 返回一个子类型的实例...
  • ThreadFactory 作用

    千次阅读 2018-05-30 16:02:52
    异常捕获public class LoggerThreadFactory implements ThreadFactory { @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setUncaughtExceptionHandler(new Thread....
  • Abstract Factory、Builder和Factory模式的差异 采用Abstract Factory、Builder和Factory模式可以分离接口和具体实现,本文通过类比讨论三者间的差异。  下面举例说明三者间的差异,其中客户相当于模式使用者,...
  • 简介AngularJS中使用factory和service的方法 AngularJS支持使用服务的体系结构“关注点分离”的概念。服务是JavaScript函数,并负责只做一个特定的任务。这也使得他们成为维护和测试的单独实体。控制器,过滤器可以...
  • fallback和fallbackfactory区别
  • Factory Method

    千次阅读 2011-07-12 10:21:05
    一、 工厂方法(Factory Method)模式工厂方法(FactoryMethod)模式是类的创建模式,其用意是定义一个创建产品对象的工厂接口,将实际创建工作推迟到子类中。工厂方法模式是简单工厂模式的进一步抽象和推广。由于...
  • org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'paymentOrderController': Injection of autowired dependencies failed; nested exception is org.springframework.bea
  • 原文链接:  ... Factory Method模式的误区:Factory Method模式是简化版的Abstract Factory吗?  FactoryMethod是一个相对比较简单的创建型模式,但是能领悟或者用对的并不多见;很多
  • Azure Data Factory 详解

    千次阅读 2017-09-11 21:56:10
    azure data factory azure sdk
  • Factory Pattern

    2011-11-09 00:05:59
    The Factory Design Pattern is probably the most used design pattern in modern programming languages like Java and C#. It comes in different variants and implementations. If you are searchi
  • SetupFactory打包文件夹

    2017-03-12 02:55:48
    SetupFactory如何打包文件夹,并能在安装目录下显示该文件夹和文件夹中的相关文件, 请各位大神指点,步骤尽可能详细一下哦,
  • 对里面的Factory模式和Abstract Factory模式有所了解。工厂模式一般对应比较简单的模型。抽象工厂模式对应复杂点的模型。 你会建立一个专门生产Sample实例的工厂: public class Factory{ public static Sample ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 90,013
精华内容 36,005
关键字:

factory