My AbstractFactory In C #

zhaozj2021-02-16  109

// myabstractFactoryUsing System;

/// Basic Products // AbstractProductSABSTRACT CLASS FONTSSTYLE {Public String StyleString;

abstract class TablesStyle {public string stylestring;}; // RealProductsclass FontsStyleA: FontsStyle {public FontsStyleA () {stylestring = "FontsStyleA";}}; class FontsStyleB: FontsStyle {public FontsStyleB () {stylestring = "FontsStyleB";}};

Class TablesSstylea: TableSStyle {Public TableSStyle () {StyleString = "TableSStylea";}}; Class TableSStyleb: TableSstyle {public TableB: TableSStyle {public TableSstyleb ()}}}}}}}}

// Basic Products

// Style Factorys

Abstract Class Stylefactory {Abstract Public FontSstyle CreateFontSstyle (); Abstract Public TableSstyle CreateTablesSstyle ();

Class Stylea: Stylefactory {Override Public FontsStyle CreateFontSstyle () {Return New FontSstyle ();} Override Public TableSstyle CreateTablesSstyle () {Return New TablessTylea ();}};

class StyleB: StyleFactory {override public FontsStyle createFontsStyle () {return new FontsStyleB ();} override public TablesStyle createTablesStyle () {return new TablesStyleB ();}}; // Style Factorys

// HomePage is The Product As LastClass HomePage {Private FontsStyle FontsStyle; Private TableSstyle Table;

Private string htmlcode = "

HelloWorld! ";

public HomePage (StyleFactory stylefactory) {fontsstyle = stylefactory.createFontsStyle (); tablesstyle = stylefactory.createTablesStyle (); htmlcode = htmlcode.Replace ( "fontsstyle", fontsstyle.stylestring); htmlcode = htmlcode.Replace ( "tablesstyle", tablesstyle. Stylestring);} public void printhtmlcode () {console.writeline (htmlcode);} public void setStyle (String filename) {}

}

// MyAbstractFactory Appclass TestApp {public static void Main (string [] args) {StyleFactory stylea = new StyleA (); HomePage samplepage = new HomePage (stylea); samplepage.PrintHTMLCode ();

Stylefactory styleb = new styleb (); Samplepage = new homepage (styleb); samplepage.printhtmlcode (); while (true) {}}};

转载请注明原文地址:https://www.9cbs.com/read-10286.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.042, SQL: 9