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 7685591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:17:06+00:00 2026-05-31T19:17:06+00:00

Let’s say I have a program to write text into a file (not really

  • 0

Let’s say I have a program to write text into a file (not really but that’s easier to explain). I want a seperate class for each filetype like PdfType and WordType that inherit from a FileTypeMaster.

FileTypeMaster (base)
-PdfType : FileTypeMaster
-WordType : FileTypeMaster (same methods as pdftype but works different)

Now to the real problem… I want the user to decide on programstart what type to use.
If he wants Pdf OR Word the methodcall should look the same (because word is new and the program was just for pdf before).

How it should work for example with pdf:

static FileTypeMaster MyFavoriteType; //declare a general var 
MyFavoriteType = new PdfType(); //cast general var to the wanted type
MyFavoriteType.CompileThis();

How it should work with word:
the same but MyFavoriteType = new WordType();`

  • 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-05-31T19:17:08+00:00Added an answer on May 31, 2026 at 7:17 pm

    Interfaces are made for that.
    MyFavoriteType should be an interface, with anything you will ever need (functions and proprieties) built in.
    Then each wanted type will implement that interface and do their own thing.

    Here is a small example:

    public interface Polygon
    {
      float GetArea();
    }
    public class Square : Polygon
    {
      float Side;
      public Square(float side)
      {
        Side = side;
      }
      Polygon.GetArea()
      {
        return side*side;
      } 
    }
    

    You can now do something like so:

    Polygon MyPolygon = new Square(5f);
    float area = MyPolygon.GetArea();
    

    And this will work for ANY SINGLE CLASS that correctly implements Polygon interface.
    So this is possible:

    Polygon MyPolygon = new Circle(5f);
    float area = MyPolygon.GetArea();
    

    In your case, the interface would look like so:

    public interface MyFavoriteType//or name it FileTypeMaster, since that's what you want to anme it
    {
      void CompileThis();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
Let's say i have this block of code, <div id=id1> This is some text
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let's say I have multiple requirements for a password. The first is that the
Let's say that I have a date in R and it's formatted as follows.
I have a French site that I want to parse, but am running into
Let's say that I have a model that handles recipes, and I want to
Let's say I have a list of objects TheListOfObjects. If I write this: TheListOfObjects
Let's say I have the string: hello world; some random text; foo; How could
Let say I have some code HTML code: <ul> <li> <h1>Title 1</h1> <p>Text 1</p>

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.