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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:03:49+00:00 2026-05-14T05:03:49+00:00

Suppose I have the following class: class Camera { public Camera( double exposure, double

  • 0

Suppose I have the following class:

class Camera
{
    public Camera(
        double exposure,
        double brightness,
        double contrast,
        RegionOfInterest regionOfInterest)
    {
        this.exposure = exposure;
        this.brightness = brightness;
        this.contrast = contrast;
        this.regionOfInterest = regionOfInterest;
    }

    public void ConfigureAcquisitionFifo(IAcquisitionFifo acquisitionFifo)
    {
        // do stuff to the acquisition FIFO
    }

    readonly double exposure;
    readonly double brightness;
    readonly double contrast;
    readonly RegionOfInterest regionOfInterest;
}

… and a DTO to transport the camera info across a service boundary (WCF), say, for viewing in a WinForms/WPF/Web app:

using System.Runtime.Serialization;

[DataContract]
public class CameraData
{
    [DataMember]
    public double Exposure { get; set; }

    [DataMember]
    public double Brightness { get; set; }

    [DataMember]
    public double Contrast { get; set; }

    [DataMember]
    public RegionOfInterestData RegionOfInterest { get; set; }
}

Now I can add a method to Camera to expose its data:

class Camera
{
    // blah blah

    public CameraData ToData()
    {
        var regionOfInterestData = regionOfInterest.ToData();

        return new CameraData()
        {
            Exposure = exposure,
            Brightness = brightness,
            Contrast = contrast,
            RegionOfInterest = regionOfInterestData
        };
    }
}

or, I can create a method that requires a special IReporter to be passed in for the Camera to expose its data to. This removes the dependency on the Contracts layer (Camera no longer has to know about CameraData):

class Camera
{
    // beep beep I'm a jeep

    public void ExposeToReporter(IReporter reporter)
    {
        reporter.GetCameraInfo(exposure, brightness, contrast, regionOfInterest);
    }
}

So which should I do? I prefer the second, but it requires the IReporter to have a CameraData field (which gets changed by GetCameraInfo()), which feels weird. Also, if there is any even better solution, please share with me! I’m still an object-oriented newb.

  • 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-14T05:03:50+00:00Added an answer on May 14, 2026 at 5:03 am

    I would generally say no, they shouldn’t, because DTOs are specific to a service or application, whereas the domain model is your “innermost” layer and should have no dependencies. DTOs are an implementation detail of something other than the domain model, and therefore, it’s breaking the abstraction for your domain model to know about them.

    Have you considered looking at AutoMapper for this? You’ll end up writing a lot less code that way. In this case, I think you’d be able to get away with simply:

    Mapper.CreateMap<RegionOfInterest, RegionOfInterestData>();
    Mapper.CreateMap<Camera, CameraData>();
    

    And later on:

    CameraData cd = Mapper.Map<Camera, CameraData>(camera);
    

    This not only reduces the code churn but compartmentalizes the mapping code in its own “mapping layer” – you have one or several modules that register these mappings that you can put in whichever assembly really uses the DTOs.

    And of course you can always create extension methods to simplify the actual mapping:

    public static class CameraExtensions
    {
        public static CameraData ToCameraData(this Camera camera)
        {
            return Mapper.Map<Camera, CameraData>(camera);
        }
    }
    

    Which makes the whole thing as simple as writing camera.ToCameraData(), but without creating a hard dependency between the domain object (Camera) and the DTO (CameraData). You have basically all of the ease-of-use of your original version, but without the coupling.

    If you’re creating these dependencies because you’re trying to create the CameraData object from private Camera data which isn’t exposed publicly then my immediate reaction would be, something’s not quite right about this design. Why not expose read-only properties on the Camera object? If you’re giving the outside world access to them anyway, through the ToData method, then you’re clearly not hiding this information, you’re just making it more cumbersome to get to.

    What if you decide 3 months down the road that you need a different kind of DTO? You shouldn’t have to modify your domain-centric Camera object every time you want to support a new use case. Better, in my opinion, to put a few read-only public properties in the class so that mappers can get access to the attributes they need.

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

Sidebar

Related Questions

Suppose I have the following: class dataClass { public: int someData; float moreData; void
Suppose I have the following class: public class TestBase { public bool runMethod1 {
Suppose you have following class: class ProcessController { public List<Process> Active { get {
Suppose i have the following class. public class Location { public Id { get;
Suppose I have the following class: public class FixExpr { Expr<FixExpr> in; } Now
Suppose I have the following class package { import flash.display.Stage; public class CustomObject {
Suppose I have the following class: public class Foo { private List<Integer> list =
Suppose I have the following class. public class gen<T> { public gen(){ } Class<T>
Suppose I have the following classes: class X; class Y; class Collection { public:
Suppose I have the following hierarchy: class A { public: A() private: int aa;

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.