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

  • Home
  • SEARCH
  • 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 4332182
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:13:11+00:00 2026-05-21T10:13:11+00:00

Below is my attempt at implementing the factory method design pattern using F# whilst

  • 0

Below is my attempt at implementing the factory method design pattern using F# whilst trying to make it a little more functional (i.e. not a straight OO implementation). Below is what I came up with:

type ISkateBoard = abstract Model : unit -> string

type SkateBoard = 
| Roskopp 
| Peters
    interface ISkateBoard
        with member this.Model() = 
                match this with 
                | Roskopp-> "Rob Roskopp..."
                | Peters -> "Duane Peters..."

let assemble model : ISkateBoard =
    match model with
    | "Roskopp" -> Roskopp :> ISkateBoard
    | "Peters" -> Peters :> ISkateBoard
    | _ -> failwith "no such skateboard model.."

let SkateBoardFactory assemble model = assemble model

let SantaCruzFactory = SkateBoardFactory assemble

Is this an appropriate implementation of the factory method design pattern? Is the pattern used in real world F# applications?

  • 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-21T10:13:12+00:00Added an answer on May 21, 2026 at 10:13 am

    I’m not sure to what extent is the factory method design pattern useful in functional programming.
    The goal of the pattern is to hide the creation of objects, so that you can work with just an abstract representation of the object.

    • When you use F# in the functional way, you’ll use concrete representations most of the time. For example, this gives you the ability to pattern match on the skateboard type.
    • Of course, F# allows you to mix functional style with object-oriented style. For some purposes, OO style works well in F#. In that case, your approach looks quite reasonable.

    Your factory method could take a concrete type (e.g. discriminated union) as an argument, instead of string. Then the task of the factory is to build abstract representation from the concrete representation:

    // Abstract representation of the data
    type ISkateBoard = 
      abstract Model : unit -> string
    
    // Concrete representation of the data
    type SkateBoard = 
      | Roskopp 
      | Peters
    

    Now, a factory would be simply a function of type SkateBoard -> ISkateBoard. For example (using F# object expressions):

    // Transform concrete representation to abstract representation 
    let factory concrete = 
      match concrete with
      | Roskopp -> { new ISkateBoard with 
                       member x.Model() = "Rob Roskopp..." }
      | Peters -> { new ISkateBoard with 
                      member x.Model() = "Duane Peters..." }
    

    I think that the benefit of this approach is that you can do some work on the concrete representation of the type (e.g. some calculation where you need pattern matching), but then you can use the factory to turn the concrete type into an abstract type.

    This matches quite well with the usual approach in functional programming – you often use differenet representations of one data and transform between them (depending on which representation is better for a particular problem).

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

Sidebar

Related Questions

Below I have a very simple example of what I'm trying to do. I
In an attempt to clean up a lot of repeated code, I tried implementing
I'm implementing LiveID authentication on my website. I've done it before, but not on
I'm implementing Cloneable with one of my classes, and I need to make a
In an attempt to organize my code, I'm trying to split up my (lengthy)
I am trying to attempt my first Google Chrome Extension and have a question.
The following XAML (below) defines a custom collection in resources and attempts to populate
Below are two ways of reading in the commandline parameters. The first is the
Below is my current char* to hex string function. I wrote it as an
Below is part of the XML which I am processing with PHP's XSLTProcessor :

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.