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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:03:47+00:00 2026-05-27T15:03:47+00:00

I have an interface named IDeviceId that I use in my domain. I also

  • 0

I have an interface named IDeviceId that I use in my domain. I also have several concrete classes that implement IDeviceId. Each concrete class contains the logic for a specific type of DeviceId. For example, I have DeviceMacId, which is simply a valid MAC address. Another concrete class is DeviceShortMacId, which takes the last 6 digits of a valid MAC address and combines it with a fixed 6-character prefix to create a valid MAC (several legacy apps use only the last 6 digits). I have a few other classes for expressing an ID, but the majority of them are all derivatives of the same data.

I’d like to be able to easily convert from any one of these classes to another. My first thought was to create a static class and do something like DeviceIdConverter.ToDeviceShortMacId(IDeviceId).

What’s the best way be able to easily accept data in one form, and then convert it to another in a repeatable fashion (across multiple apps)?

  • 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-27T15:03:48+00:00Added an answer on May 27, 2026 at 3:03 pm

    I don’t think there is a “best way” to do this, you’re going to have to find a pattern that works for you and go with it.

    Off the top of my head, based on the examples you presented I would do something like:

    interface IDeviceId
    {
        // Other methods
        IDeviceId ToDeviceShortMacId(IDeviceId);
        IDeviceId ToDeviceMacId(IDeviceId);
        // etc...
    }
    

    Then each of the classes would need to implement the conversion methods. Now if you plan on adding a lot of other implementation (concrete) classes later, then this could get pretty verbose. So what you might consider in that case is in each of the projects which creates a new implementation you also create extension methods like:

    public static class MacDeviceIdExtensions
    {
    public static DeviceMacId ToDeviceMacId(this IDeviceId deviceId) 
    {
        // Implement conversion
    }
    public static DeviceShortMacId ToDeviceMacId(this IDeviceId deviceId) 
    {
        // Implement conversion
    }
    }
    

    The extension methods approach is a lot more modular, but could also be a lot more code.

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

Sidebar

Related Questions

Let's suppose I have an interface named Controller. Several classes implement this interface and
I have the following situation: Three concrete service classes implement a service interface: one
I have the following classes: public interface Emailer {} @Named public class RealEmailer implements
I have an interface named IEntity which till now has one concrete class named
I have seen that if I have interface named interfaceABC. Example: public class ABController
I have an interface IServiceInfo and an abstract class ServiceInfo. There are several classes
I have interface IDoc and an abstract class that implements it named Doc. I
I have 2 classes, Parent and Child, and Parent has a class method named
Here's an odd one. I have a class named TileMap with the following interface:
I have an interface named SHAPE . CIRCLE and RECTANGLE are two classes implementing

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.