Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

Wednesday, May 1, 2013

Published 11:14 PM by with 1 comment

Factory Pattern - [Creational Patterns]



Factory Pattern

Logical Model

As with other design patterns, there are countless variations of the Factory pattern, although most variants typically used the same set of primary actors, a client, a factory, and a product. The client is an object that requires an instance of another object (the product) for some purpose. Rather than creating the product instance directly, the client delegates this responsibility to the factory. Once invoked, the factory creates a new instance of the product, passing it back to the client. Put simply, the client uses the factory to create an instance of the product. Bellow shows this logical relationship between these elements of the pattern.





abstract class Page
{
}

class Education : Page
{
}

class SkillPage : Page
{
}

class Experiance : Page
{
}

//----
abstract class Document
{
private List<Page> _pages = new List<Page>();

        public abstract void CreatePages();

        public Document()
        {
            this.CreatePages();
        }

        public List<Page> Page
        {
            get { return _pages; }
        }
    }

class Resume : Document
{
   public override void CreatePages()
   {
Page.Add(new Education());
       Page.Add(new SkillPage());
       Page.Add(new Experiance());
   }
}

 

Read More
    email this       edit

Monday, April 29, 2013

Published 10:21 PM by with 0 comment

Abstract methods



Abstract methods

When an instance method declaration includes an abstract modifier, that method is said to be an abstract method. Although an abstract method is implicitly also a virtual method, it cannot have the modifier virtual.

An abstract method declaration introduces a new virtual method but does not provide an implementation of that method. Instead, non-abstract derived classes are required to provide their own implementation by overriding that method. Because an abstract method provides no actual implementation, the method-body of an abstract method simply consists of a semicolon.

Abstract method declarations are only permitted in abstract classes

public abstract class AbstractClass
{
public abstract void PrintName();
}

Implementation

public sealed class AbstractImp1:AbstractClass
{
public override void PrintName()
       {
           Console.WriteLine("Im Aruna");
}
}

Calling

AbstractClass abs = new AbstractImp1();
abs.PrintName();

Read More
    email this       edit

Thursday, December 20, 2012

Published 8:26 PM by with 0 comment

Spelling Check In Testbox

this is a usefull method to check spelling in testbox

//make all references
Microsoft Office 12.0 Object Library
Microsoft Word 12.0 Object Library


using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using System.Web.UI.WebControls;
using Microsoft.Office.Interop.Word;



public void SpellChecking(TextBox tBox)
{
try
{
Application app = new Application();
if (tBox.Text.Length &gt; 0)
{
app.Visible = false;
object template = Missing.Value;
object newTemplate = Missing.Value;
object documentType = Missing.Value;
object visible = false;
object optional = Missing.Value;
_Document doc = app.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible);
doc.Words.First.InsertBefore(tBox.Text);
ProofreadingErrors we = doc.SpellingErrors;
doc.CheckSpelling(ref optional, ref optional, ref optional,
ref optional, ref optional, ref optional, ref optional,
ref optional, ref optional, ref optional,
ref optional, ref optional);
object first = 0;
object last = doc.Characters.Count - 1;
tBox.Text = doc.Range(ref first, ref last).Text;
}
object saveChanges = false;
object originalFormat = Missing.Value;
object routeDocument = Missing.Value;
app.Quit(ref saveChanges, ref originalFormat, ref routeDocument);
}
catch (Exception ex)
{
//what ever u want to display on error
}
}
Read More
    email this       edit