eysidi
eysidi
Explore posts from servers
CC#
Created by eysidi on 2/28/2024 in #help
Dependency Inversion
Would generics help?
40 replies
CC#
Created by eysidi on 2/28/2024 in #help
Dependency Inversion
Not sure how else to deal with varying number of Vector2 s returned
40 replies
CC#
Created by eysidi on 2/28/2024 in #help
Dependency Inversion
I think I will just create static methods for each shape
c#
public class CoordinateCalculator
{
static Vector2 CalculateCircleCoords(Vector2 position) => position;

static (Vector2, Vector2) CalculateRectCoords(Vector2 position)
{
// Calc here
return (Vector2 pMin, Vector2 pMax);
}

...
}
c#
public class CoordinateCalculator
{
static Vector2 CalculateCircleCoords(Vector2 position) => position;

static (Vector2, Vector2) CalculateRectCoords(Vector2 position)
{
// Calc here
return (Vector2 pMin, Vector2 pMax);
}

...
}
40 replies
CC#
Created by eysidi on 2/28/2024 in #help
Dependency Inversion
I will try again and see what I come up with
40 replies
CC#
Created by eysidi on 2/28/2024 in #help
Dependency Inversion
I already can just write the code and keep on going, as I said my goal is to apply SOLID principles 🙂
40 replies
CC#
Created by eysidi on 2/28/2024 in #help
Dependency Inversion
let's consider this is an interview question You get Vector2 position as argument, create classes/interfaces for Shape where each shape takes different number of position arguments Circle -> 1 Square -> 2 Triangle -> 3 MyWeirdShape -> N What classes/interfaces would you create that applies SOLID
40 replies
CC#
Created by eysidi on 2/28/2024 in #help
Dependency Inversion
so I have
c#
void Draw(Vector2 position);
c#
void Draw(Vector2 position);
I pass 300x500 for example, find the center, calculate Vectors for the shape
40 replies
CC#
Created by eysidi on 2/28/2024 in #help
Dependency Inversion
this is not the case though,
c#
ImGui.AddCircle(Vector2 pos);
ImGui.AddTriangle(Vector2 p1, Vector2 p2, Vector3);
ImGui.AddRect(Vector2 pMin, Vector2 pMax);
c#
ImGui.AddCircle(Vector2 pos);
ImGui.AddTriangle(Vector2 p1, Vector2 p2, Vector3);
ImGui.AddRect(Vector2 pMin, Vector2 pMax);
you see each shape has different position requirements,
40 replies
CC#
Created by eysidi on 2/28/2024 in #help
Dependency Inversion
so the solution is abstracting the Calculator
40 replies
CC#
Created by eysidi on 2/28/2024 in #help
Dependency Inversion
sure I can just implement my calculation under Draw implementation but as I said I won't be able to test
40 replies
CC#
Created by eysidi on 2/28/2024 in #help
Dependency Inversion
I understand, have already thought of the logic and had asked this question. Was responded I need dependency inversion which made/makes sense. I'm trying to practice SOLID so want to implement things correctly.
40 replies
CC#
Created by eysidi on 2/28/2024 in #help
Dependency Inversion
calculation of the coordinate for each shape
40 replies
CC#
Created by eysidi on 2/28/2024 in #help
Dependency Inversion
because Draw returns nothing and I can't create a unit test for it
40 replies
CC#
Created by eysidi on 2/28/2024 in #help
Dependency Inversion
however I want to apply dependency inversion and be able to test my code
40 replies
CC#
Created by eysidi on 2/28/2024 in #help
Dependency Inversion
I definetely can do the calculation under Draw implementation of each shape
40 replies
CC#
Created by eysidi on 2/28/2024 in #help
Dependency Inversion
I'm using IMGui so, for circle I need single Vector2 for square I need pMin pMax 2 Vector2s for triangle I need 3 Vector2s
40 replies
CC#
Created by eysidi on 8/28/2023 in #help
❔ Serializing related object EF
I see, thanks a lot for your help
47 replies
CC#
Created by eysidi on 8/28/2023 in #help
❔ Serializing related object EF
I have seen some examples where related model is declared as virtual
public class City {
...
public virtual Coordinates Coordinates { get; set; }
}
public class City {
...
public virtual Coordinates Coordinates { get; set; }
}
What does virtual do in this case? Which one is correct?
47 replies
CC#
Created by eysidi on 8/28/2023 in #help
❔ Serializing related object EF
I removed City from Coordinates
47 replies