Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8217595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:30:45+00:00 2026-06-07T12:30:45+00:00

I am a beginner in .net. I’m trying to understand the fabric pattern method.

  • 0

I am a beginner in .net. I’m trying to understand the fabric pattern method.

I found this code example:

   public abstract class Person
{
    public string Name { get; set; }
    public decimal Salary { get; set; }
}

public class Employee : Person
{
    public Employee()
    {
        this.Salary = 20000;
    }

}

public class Pilot : Person
{
    public string PilotNumber { get; set; }

    public Pilot()
    {
        this.Salary = 50000;
    }
}

public static class PersonFactory
{
    public static Person CreatePerson(string typeOfPerson)
    {
        switch (typeOfPerson)
        {
            case "Employee":
                return new Employee();
            case "Pilot":
                return new Pilot();
            default:
                return new Employee();
        }
    }
}

And to use the factory:

Person thePilot = PersonFactory.CreatePerson("Pilot");
    ((Pilot)thePilot).PilotNumber = "123ABC";

I can’t understand CreatePerson method in this example.

public static Person CreatePerson(string typeOfPerson)
    {
        switch (typeOfPerson)
        {
            case "Employee":
                return new Employee();
            case "Pilot":
                return new Pilot();
            default:
                return new Employee();
        }
    }

The method returns Person type, but in switch operator as you can see it’s creates and returns Pilot() or Employee() instance class.

How can this be that the return type definitions in the method’s signature is different from the return type of the function itself.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T12:30:48+00:00Added an answer on June 7, 2026 at 12:30 pm

    Because all of these return types inherit from Person. You can implicitly return a derived class from a function.

    public class Employee : Person <------ this Employee is inheriting the abstract class 'Person' (but not implementing anything from it)
    {
        public Employee()
        {
            this.Salary = 20000;
        }
    
    }
    

    e.g. above – the Employee class is actually a Person too since it inherits from the abstract class (it actually doesn’t implement anything from the abstract class as there is nothing to implement)

    The Person class here is abstract yet it doesn’t specify any abstract members – is this just test code?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a beginner level question for asp.net MVC I have the following code
I am a total total beginner in Java actually I am .net dev trying
I'm a beginner at this. I'm using mysql connector .net to connect vb.net with
I'm an absolute beginner with ASP.NET[MVC] so this is probably a dumb question. I
Good Morning everybody. I'm a beginner in .Net languages and need an example to
I am absolute beginner in C#, ASP.NET and MVC2 and this means that I
This is a ASP.NET MVC beginner question (I'm in phase of developing NerdDinner )...
VB.NET level: Beginner I made a .exe using VB.NET. In this program there are
I'm a beginner in ASP.NET 2.0.Probably this could sound too basic and stupid issue
I'm beginner in Asp.Net and Im trying to display gc on reapet control. Here's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.