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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:46:04+00:00 2026-05-22T22:46:04+00:00

I am reading Head First Design Pattern and at chapter of Factory. I am

  • 0

I am reading Head First Design Pattern and at chapter of Factory. I am thinking to change one my working code to implement it.

First I create IAction and ActionFactory with GetAction, from IAction I create UploadDatabase, CopyFile, UploadSharepoint, etc. This is in DLL and can be call from a exe. This is easy and done.

Then I plan to create AutoCADAction from IAction which include action like Print, Script, etc. Those actions only can be run inside AutoCAD.

Now I like to create AutoCADActionFactory with override GetAction, it will creaet ActionFactory’s, and AutoCADAction as well. Now I lost.

Here is the sample code:

In ActionFactory.GetAction

public IAction GetAction(ActionType myActionType)
{
    switch (myActionType)
    {
        case ActionType.UploadDatabase:
            return new UploadDatabase();

        case ActionType.CopyFile:
            return new CopyFile();

        case ActionType.UploadSharepoint:
            return new UploadSharepoint();
    }
}

How I code my AutoCADActionFactory.GetAction, Is this correct?

public AutoCADAction GetAction(ActionType myActionType)
{
    return Base.GetAction;
    switch (myActionType)
    {
        case ActionType.Print:
            return new Print();

        case ActionType.Script:
            return new Script();

        ...

    }
}

Thank you,

  • 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-22T22:46:05+00:00Added an answer on May 22, 2026 at 10:46 pm

    I’m not completely convinced that a Factory, or more correctly a Factory Method (as you appear to be trying to use it) is the correct choice here. The reason I say that is you seem to have overlooked some things.

    Typically, a Factory Method makes most sense when you will be performing operations that are doing similar things – for example reading a bitmap image from a file in various formats. The actions you have defined seem to vary widely, and I’m not convinced they should represent the same type of operation (i.e. support the same interface). Of course, there is no reason why your actions shouldn’t support multiple interfaces (e.g. the Print class may implement both IAction and IPrint), but without additional information, I do wonder if the underlying design is as solid as it should be.

    Because you are using the same ActionType enumeration in the ActionFactory and the AutoCADActionFactory you probably want / need to define a “null” action that is returned by the ActionFactory. (Depending on the context, you may want that null action to do something useful – like pop up a message box saying “That operation is not supported in this context”, but it could just as easily do nothing at all.) The null action should be returned in the “Default” case.

    As currently coded, you will always return the action from the base class. You probably want something that looks more like this:

    public AutoCADAction GetAction(ActionType myActionType)
    {
        switch (myActionType)
        {
            case ActionType.Print:
                return new Print();
    
            case ActionType.Script:
                return new Script();
    
            default:
                return base.GetAction(myActionType);
        }
    }
    

    This would allow you to completely replace the action provided by the ActionFactory (which I imagine would be the most likely thing to want), or to do specialized things like returning a specialized action which performs some specific operation in addition to the action from the base class.

    You may also want to consider the common Object Oriented principle to “Favor Encapsulation over Inheritance”. In this case, I don’t see any real benefit in inheriting from ActionFactory. In the case of an Abstract Factory class, where there are separate calls for each action type, inheritance provides greater benefit.

    Does any of this help?

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

Sidebar

Related Questions

i'm reading this book (Head First Object Oriented Design & Analysis). In chapter 5
I am learning design pattern by reading Head First Design Patterns , and I
I am reading the Head First Android development book. In the third chapter where
After reading the most excellent book Head First Design Patterns, I began proselytizing to
I'm currently reading Head First's Object Oriented Analysis and Design. The book states that
I'm reading through head first design patterns at the moment and while the book
After reading the Head First Design Patterns book and using a number of other
I'm reading Head First Design Patterns and have some understanding in Java. It starts
I'm really new at Ruby on Rails development. I'm reading Head First Rails and
I started learning rails a few days ago and I'm reading head first rails

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.