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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:16:17+00:00 2026-05-14T07:16:17+00:00

I am thinking through a nice pattern to be useful across domains of measurable

  • 0

I am thinking through a nice pattern to be useful across domains of measurable units (ie, Length, Time) and came up with the following use case and initial classes, and of course, questions!

1) Does a Composite pattern help or complicate?
2) Should the Convert method(s) in the ComposityNode be a separate converter class?

All comments appreciated. Cheers,
Berryl

Example Use Case:

var inch = new ConvertableUnit("inch", 1)
var foot = new ConvertableUnit("foot", 12)
var imperialUnits = new CompositeConvertableUnit("imperial units", .024)
imperialUnits.AddChild(inch)
imperialUnits.AddChild(foot)

var meter = new ConvertableUnit("meter", 1)
var millimeter = new ConvertableUnit("millimeter ", .001)
var imperialUnits = new CompositeConvertableUnit("metric units", 1)
imperialUnits.AddChild(meter)
imperialUnits.AddChild(millimeter)

var oneInch = new Quantity(1, inch);
var oneFoot = new Quantity(1, foot);
oneFoot.ToBase() //  "12 inches"

var oneMeter = new Quantity(1, meter);
oneInch.ToBase() //  .024 meters

Possible Solution

ConvertableUnit : Node  
  double Rate
  string Name

Quantity
  ConvertableUnit Unit
  double Amount

CompositeConvertableUnit : Node
  ISet<ConvertableUnit> _children
  ConvertableUnit BaseUnit {get{ return _children.Where(c=>c.Rate == 1).First() } } 
  Quantity ConvertTo(Quantity from, Quantity to)
  Quantity ToBase(Quantity from);
  • 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-14T07:16:18+00:00Added an answer on May 14, 2026 at 7:16 am

    I don’t really see any benefit to using the composite pattern here. From wikipedia:

    Composite allows a group of objects to be treated in the same way as a single instance of an object.

    You don’t need groups of converter objects, a list of converters would be enough.

    As for the Convert method – I would say converting is why the class exists, to probably a good place for it.

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

Sidebar

Related Questions

I was thinking through some DAO design stuff with a teammate and came across
I am thinking through the layout of my Person table in my MSSQL DB.
I have just done something without thinking it through. I have made a branch
Im thinking about building an application on our website to track order places through
Thinking about avoiding code replication, I got a question that catches me every time
Im thinking about to use a DB for my logs instead of a normal
I am having some troubles thinking through a design issue and thought that the
I've been thinking that it would be nice to create midori plugins with haskell,
This isn't a complicated question. I was just thinking through best practice and thought
I have an application whose primary function works in real time, through websockets or

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.