TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Upkar Srivastava
NA
9
965
Decide to instantiate classes at run time with different pro
Jul 18 2014 2:00 PM
nterface InterfaceToimplement
{
string Name { get; set; }
}
Implementing Classes
class Student:InterfaceToimplement
{
public string Name { get; set; }
public int ID { get; set; }
public int RollNumber { get; set; }
}
class Room : InterfaceToimplement
{
public string Name { get; set; }
public int Length { get; set; }
public int Breadth { get; set; }
public int Height { get; set; }
}
class Account : InterfaceToimplement
{
public string Name { get; set; }
public string AccountholderName { get; set; }
public int AccountID { get; set; }
public int Amount { get; set; }
}
Factory Class
class ClassFactory
{
public InterfaceToimplement GetClass(string classname)
{
InterfaceToimplement ObjectClass = null;
switch (classname)
{
case "Student":
ObjectClass = new Student();
break;
default:
break;
}
return ObjectClass;
}
}
Calling Method
static void Main(string[] args)
{
string classname = "Student";
ClassFactory clsfactory = new ClassFactory();
InterfaceToimplement GetObjIntrface = null;
GetObjIntrface = clsfactory.GetClass(classname);
}
When I use GetObjIntrface. Then i use only properties of interface but i want all the properties of class Student. Suggest right approch
Reply
Answers (
3
)
Inserting object into excel using c#
How to read 2-D barcode from the pdf file