ER Diagram And Domain Model

“Take any business of your choice, analyze the Problem domain, choose only one and draft the ER Diagram”

I’ve been stuck with this question for a couple of days now since my teacher told me to work on, I’m pretty confused and don’t know how to go about it

design – How to structure a Canonical Model?

I have an integration to several different, but similar sites. All these sites return data that is semantically the same, but represented differently. Because of this, I need a single canonical representation that I define, and then parse each integration to this representation.

Example:
Site 1 Site 2 Site 3 My model
Cow milk Fresh milk milk Milk

So I am going to store mapping tables for each site, that can convert/deconvert to my canonical model. This is all fine, but I am torn on how to implement this. Should my canonical model be represented as an Enum or simply as Strings, or something else?

If it is just Strings, the solution is a bit more dynamic, since I can add a new item as a new record in the database. If I go with the Enum solution, I would need to add code for each new item.

As it is right now, I struggle to identify potential needs for having it as an Enum, though intuitively, it feels more typed and safe.

Properties

  • The list of items is finite, but probably >1000
  • The list is well defined, and free text is not needed

nikon – Why can I recover more highlight detail from a predecessor model?

I took the same image with a Nikon D800 and a D850. The D850 is the successor of the successor (the D810) of the D800. Here are both images in Lightroom (they have different white balances):

enter image description here

As you can see the highlights around the lantern look about the same. However when I dial in +2.2 exposure and -100 highlights in Lightroom things look different:

enter image description here

The amount of recovered detail behind the glare differs a lot. Is it possible that this is due to Lightrooms interpretation of the RAW files of both cameras? Or is this a matter of dynamic range? I dont think the D850 should not have less dynamic range then the D800. In fact Ive read they should have about the same amount of usable dynamic range and this is what I would agree with from my experience so far.

I used the same exact lens on both cameras.

Unable to generate the model because of the following exception: ‘System.ArgumentException: ”, valor hexadecimal 0x08, é um caractere inválido

Ao tentar gerar a camada de modelo de um banco de dados já existente (Sql server) recebo este erro. O que devo fazer ?

Ao tentar gerar a camada de modelo de um banco de dados já existente (Sql server) recebo este erro. O que devo fazer ?

java – Do I have LocalDTOs? If yes, what is a good approach to keep encapsulation of the domain model?

LocalDTO term refers to Fowler’s article.

Say I have a domain entity Person:

public class Person {
    private String id;
    private String name;
    private int age;
}

This entity has its own semantics in the domain & application layer and has its behavior. In other words, it is not an anemic model.

Now I have a presentation class (assume an MVController or an MVPresenter) that needs to show a list of Persons and have a form that user fills to update a stored Person.

That’s why I currently have the following contract.

public interface PersonService {
    List<PersonDto> getPersons();

    void updatePerson(PersonDto personDto);
}

And now my presentation class depends on person service. It does not know that Person class exists and does not have not access to the domain world. I am aware that this is good thing.

However, the application is a desktop application. Fowler in his article says that DTO’s should be used for remote communication (I understand why). In a desktop application, there is no remote communication (actually there is – I use DTOs there anyway). So my question, is this PersonDto a LocalDTO?

If I follow Fowler’s advice:

start with a locally invocable Service Layer whose method signatures
deal in domain objects

I end up with:

public interface PersonService {
    List<Person> getPersons();

    void updatePerson(Person p);
}

I have the following problem: The presentation class will be able to call (say for example) person.setAge(int x). Which something I want to avoid since I consider this a “leakage”. Also, to the application, calling setAge does only the validation. It does not have a meaning if this person is not persisted (passed to the service).

In order to avoid this leakage and make the domain entity read-only, I can have the setter package private. Then service can manipulate Person objects and presentation class can only read from them. Which is great.

However, there is a problem with this approach as well. Testing. Testing the presentation classes require to create models. For example, given a person, is its name and age on the form? If Person objects are read only in presentation layer, I cant create Person objects for (in) presentation layer tests. But if I had DTOs, who cares? Just new PersonDto.

So what is the solution? DTO’s?

unity – Model missed by both EventSystem.current.RaycastAll and IPointerClickHandler when scaling time

I have a situation where a model is ignored in favour of one behind it. The rear model is returned by EventSystem.current.RaycastAll, and the front model’s IPointerClickHandler callback isn’t triggered if the rear model is present. The rear model does not implement IPointerClickHandler (or pointer up/down handlers, etc). Both these things work on the front model if the rear model isn’t there.

Debugging shows that the Raycast is only returning one result. By comparing behaviour when the rear model is and isn’t present, I can verify that the distance value in the RaycastResult is greater when hitting the rear model than when hitting the front model.

I can “fix” the problem by using the Inspector to disable and re-enable the front model.

Here’s the problem and the “fix” in action:

Tooltips fixed by disabling and re-enabling an object

Higher quality version here.

EventSystem.current.RaycastAll is used to power the tooltips, and IPointerClickHandler is (unsurprisingly) used to get the cube model to react to clicks.

Update: After more investigation, I’ve made limited progress:

  • I’ve fixed the problem when running the game at normal speed by giving both objects a kinematic Rigidbody.
  • However, the problem still occurs when I speed up time. I set Time.timeScale, and increase Time.fixedDeltaTime by the same scale factor as recommended here.
  • I can eliminate the problem by not changing Time.fixedDeltaTime, however I’m reluctant to do so since this has a big impact on framerates at higher speeds (12x being the highest available).

enter image description here

Again, higher quality version here

Unity version: 2020.3.11f1

Update 2: As requested, here’s the raycast and time scaling code:

public class TooltipDisplay : MonoBehaviour {
    public void FixedUpdate() { // I've tried it in Update too, no change
        PointerEventData pointerData = new PointerEventData(EventSystem.current);
        pointerData.pointerId = -1;
        pointerData.position = Mouse.current.position.ReadValue();
        List<RaycastResult> results = new List<RaycastResult>();
        EventSystem.current.RaycastAll(pointerData, results);
        Tooltip highest = null;
        foreach (var result in results) {
            // There's only one result here, and it's often the wrong one :(
            Tooltip t = GetTooltip(result.gameObject);
            if (t == null) continue;
            if (highest == null || t.priority > highest.priority) {
                highest = t;
            }
        }
        // If we found a tooltip, display it.
        // ...
        // ...
    }
}


public class SpeedLimiter {
    
    private int multiplier;
    private static readonly float DEFAULT_FIXED_DELTA_TIME = Time.fixedDeltaTime;
    public const float SECONDS_PER_COMMAND = 2.0f;
    public float timeAccumulated { get; private set; }
    
    // Called from a Unity Button press (bottom-right of video) or from an Input system keypress handler.
    public void SetMultiplier(int speed) {
        multiplier = speed;
        Time.timeScale = multiplier;
        Time.fixedDeltaTime = DEFAULT_FIXED_DELTA_TIME * multiplier;
    }

    public bool Advance() { // Called in Update
        bool looped = false;
        timeAccumulated += Time.deltaTime;
        while (timeAccumulated >= SECONDS_PER_COMMAND) {
           timeAccumulated -= SECONDS_PER_COMMAND;
           looped = true;
        }
        return looped;
    }
}


public class UHexahedron : MonoBehaviour {
    Vector3 fromPosition;
    Vector2 toPosition;
    float translationStart;
    float translationDuration;
    bool translating;

    public void FixedUpdate() {
        if (translating) {
            float currentTime = SpeedLimited.timeAccumulated;
            if (currentTime < translationStart) return;
            if (currentTime >= translationStart + translationDuration) {
                Translate(1);
            }
            else {
                float lerp = (currentTime - translationStart) / translationDuration;
                Translate(lerp);
            }
        }
    }
    
    private void Translate(float lerp) {
        if (lerp >= 1) {
            transform.position = toPosition; // Tried rigidbody.position, no change
            translating = false;
            return;
        }
        transform.position = Vector3.lerp(fromPosition, toPosition, lerp); // Again, tried rigidbody.position, no change.
    }
}

Anemic Domain Model VS coupling and dependencies- design conflict – need an Object oriented advice

Some coupling must exist, otherwise a program would not be able to do anything (if nothing knows about anything, no calls can be made). This kind of coupling certainly exists in your “manager” classes. The thing that’s bad is coupling that makes your code hard to change, and most of it is kind of accidental.

You start with certain best practices, and a certain way of doing things; this is OK to get you off the ground, but as the project evolves, accidental coupling creeps in, and in a big part because of inertia – people blindly following generic “best practices” and “established conventions” way beyond the point of their usefulness, without stopping to rethink/redesign before it’s all a complicated mess. Best practices, conventions, linters, style checkers – that all has it’s place, but none of it automatically gives you good code. Nobody wants to write bad code, however, bad code, in large part, gets written very systematically.

So, when it comes to bad coupling, you have this kind of coupling even within your “manager” classes, as well as in and between classes that use them – it’s just not as obvious until a change causes you to modify 20 different files. They are coupled in subtle ways – like depending on a specific data format, on a specific field being there, on calling order, on things needing to match or follow the same pattern in different places, etc.

The thing that you want to do is not to eliminate coupling completely, but to minimize it and control it, and be strategic about it.

“but then we have very strong coupling and dependency for Customer with PaperBoy”

Sure, but, putting a type name in a constructor parameter list makes that type explicitly a part of the public interface of that class. It explicitly states what depends on what. Being explicit is good, and if this coupling is deliberate, and if Customer and PaperBoy are fairly small and focused classes, and not these large procedural bags of functions, than that’s a way of controling coupling.

Note that on a most basic level, the Customer class doesn’t depend on the internal implementation of PaperBoy, just on its public interface (the set of public methods, including their parameter and return types). Behind that, you can change how PaperBoy is implemented – you can change its internal code, its internal data structures, you can pull out parts of PaperBoy into a separate class, you can do all kinds of things – without affecting Customer.

If you need more flexibility than that, maybe you can derive a subtype of PaperBoy, or perhaps make the constructor parameter type be an interface instead of a concrete class.

“and changes in paperboy will cause changes in Customer”

The most likely cause of that is that you’re treating PaperBoy as just a data structure, and your Customer is pulling data out of PaperBoy to manipulate it itself, instead of telling PaperBoy what to do (by calling a method – almost in a fire and forget style). What’s happening there is that you’re not defining/constraining the way Customer talks to PaperBoy – you’re not thinking carefully (or at all) about the public interface of PaperBoy, you’re just saying “Here’s some data, hope the format doesn’t change! (wink, wink)”. This problem is not solved by having “manager” classes – changes in the data structures they depend on will have the same effect.

“if i will need my Customer in other project”

Don’t get this the wrong way, I’m by no means trying to talk down to you or anything like that, but:

skipping steps

When people say “reusable”, it really means the ability to use the same code/function/object in a different context: perhaps in a test, perhaps in a different part of the same project, or as a thing you can plug your newly developed component into. Or, if the function or class or module (or whatever) turns out to be more generally useful, perhaps in a different project, or maybe in a library.

Think about what you need for something simple like a function to be reusable. You need it to have well defined inputs and outputs. These are often data, but note that some of those inputs (and even the output) may be a functions themselves (look at the IEnumerable.Select method in C#, or Array.map in JavaScript). You need the function to not depend on obscure global variables. It’s even more reusable if it has no side effects at all. It’s similar with objects: well-defined inputs and outputs; they can take other objects (or functions, for that matter) as parameters, that they can then call; they need to be protective of their internals, but also need to limit what they know about the rest of the system.

When you can’t easily reuse something in a different context, it’s not because it’s a class coupled to some other class, it’s because it wasn’t designed to be reusable.

Now, I’m not saying that the only way to deal with this is OOP; however, whatever paradigm you’re using, these same principles apply (it’s just that their expression may take a different form). Also note that I’m not advocating for (or against) purity: some aspects of different paradigms can be mixed and can complement each other nicely. So I’m not necessarily saying that your domain model must not be anemic – just that that you have to control the coupling; if it happens in functions that work on anemic data structures, then you have to control it there.

I’ve been thinking recently, the usual advice regarding going from an anemic domain model to a proper OO design is to put behavior into those data structures; however, I think is not necessarily immediately obvious how to go about this change, even to experienced designers, but they can find their way by relying on their experience and design skills. But for someone who designed themselves into an anemic domain model, the path from one point to the other might be completely obscured.

Instead, maybe a better way to approach things is to look where your behavior is now, inside your “manager” classes, and try to decouple that. That’s where your objects hide. Keep treating your domain model as inputs and outputs for the time being, but in your procedural code, try to find groups of things that are not really related to other things, and isolate them. Find groups of lines that have a comment on top explaining what they do – extract each into a meaningfully named function. Reduce conceptual duplication (code doing the same thing, even though it’s written slightly differently) – extract those into methods. Find those member variables that are used to track things internally, but are only used by some methods. That looks like a class with some state; combine those and pull out a class.

Notice when a change causes you to modify several files. Try to understand why, and see if you can restructure things so that this proliferation doesn’t happen, especially if the kind of change that caused it is a common one – if there’s a history of similar change requests, and you can expect more in the future. Maybe some of the steps above will make such restructuring easier.

Keep doing this over time, gradually arriving to a more decoupled OO system. And remember, it’s OK for a class to be small – they should be small, and focused on a specific responsibility. Small means less opportunity for coupling, but doesn’t prevent your code from doing “bigger” things – objects achieve this through collaboration. Small and focused, with a well defined public interface and the associated rules, is what’s reusable.

Minizinc – understanding why my model runs for forever without any result for large data


Your privacy


By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.




unity – Model missed by both EventSystem.current.RaycastAll and IPointerClickHandler unless disabled and re-enabled in the Editor

I have a situation where a model is ignored in favour of one behind it. The rear model is returned by EventSystem.current.RaycastAll, and the front model’s IPointerClickHandler callback isn’t triggered if the rear model is present. The rear model does not implement IPointerClickHandler (or pointer up/down handlers, etc). Both these things work on the front model if the rear model isn’t there.

Debugging shows that the Raycast is only returning one result. By comparing behaviour when the rear model is and isn’t present, I can verify that the distance value in the RaycastResult is greater when hitting the rear model than when hitting the front model.

I can “fix” the problem by using the Inspector to disable and re-enable the front model.

Here’s the problem and the “fix” in action:

enter image description here

Higher quality version here.

EventSystem.current.RaycastAll is used to power the tooltips, and IPointerClickHandler is (unsurprisingly) used to get the cube model to react to clicks.

Unity version: 2020.3.11f1

Unity: Model missed by both EventSystem.current.RaycastAll and IPointerClickHandler unless disabled and re-enabled in the Editor

I have a situation where a model is ignored in favour of one behind it. The rear model is returned by EventSystem.current.RaycastAll, and the front model’s IPointerClickHandler callback isn’t triggered if the rear model is present. The rear model does not implement IPointerClickHandler (or pointer up/down handlers, etc). Both these things work on the front model if the rear model isn’t there.

Debugging shows that the Raycast is only returning one result. By comparing behaviour when the rear model is and isn’t present, I can verify that the distance value in the RaycastResult is greater when hitting the rear model than when hitting the front model.

I can “fix” the problem by using the Inspector to disable and re-enable the front model.

You can find a video of the problem and “fix” in action here: https://imgur.com/a/Oku79iB

EventSystem.current.RaycastAll is used to power the tooltips, and IPointerClickHandler is (unsurprisingly) used to get the cube model to react to clicks.

Unity version: 2020.3.11f1