除了 new 之外的创建对象的方法 通过 new 创建对象,会使得程序面向实现编程,先举个例子,某个果园里现在有两种水果,一种是苹果,一种是香蕉,有客户想采摘园子里的水果,要求用get()方法表示即可 一般情况下,最直接的写法为: public class Apple { public void get() { System.out.println("得到苹果"); } } public class Banana { public void get() { System.out.p…
单例模式:DbContextFactory.cs using CZBK.ItcastOA.Model; using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Runtime.Remoting.Messaging; using System.Text; using System.Threading.Tasks; namespace CZBK.…
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 简单的工厂模式 { //我们是一个食品生产工厂,都是生成吃的 class Program { static void Main(string[] args) { var doxing= CreateFoodFactory.Cook("雪饼"); doxing.PrintFood(); var do…
工厂模式在软件工程里面是一种比较常见的设计模式了.这种模式抽象了创建具体对象的过程. 上代码: function createHuman(name,sex) { var obj = new Object(); obj.name = name; obj.sex = sex; obj.say = function () { alert(this.name); } return obj; } var man = createHuman("李白", "男"); var wo…