last day (16 days later) » 

11:31 AM
room topic changed to ILoveStackoverflow: Discussing some specific issue (no tags)
 
11:53 AM
Hello sir
 
Hi :)
 
Actually I have taken VariantProcessor code design from SO only
Can I point you out to that answer from where I have taken the design ?
 
I hope someone else will join us here. What is the idea ? What do we try to achieve ?
Sure
 
2
Q: Way to hide logic behind class for better readability of method and refactor class to follow SRP

ILoveStackoverflowI have an algorithm to create a version for an entity and then I save that version against below 2 entity: 1) Variant 2) Category interface IEntityVersion { string GetVersion(); } public class EntityVersion : IEntityVersion { public string GetVersion() { return null; }...

So idea is I have a long running process which consist of 2 steps as below :
1) Transformation :
 
May I ask what do you need this for ?
Ok go on
What do you need this algorithm for ? What is the business problem/task ?
I'd be much easier to help you if you could outline the task you're trying to accomplish
 
12:01 PM
private void Transform(Variant model)
{
  for (int counter = 0; counter < model.Subvariants.Count - 1; counter++)
  {
         var left = model.Subvariants[counter];
         var right = model.Subvariants[counter + 1];
   }
}
In transformation,I am reading data from 2 subvariants at a time from database and than performing transformation logic
Now once this tranformation is done,I want to create Versioning and save it against 2 entity :
1) Variant
 
Ok, this makes sense, please go on
 
2) Category
interface IEntityVersion
    {
        string CategoryIds { get; }
        string GetVersion();
    }

    public class EntityVersion : IEntityVersion
    {
        private string _categoryIds = "100,101,102" ;
        public string  CategoryIds => _categoryIds;
        public string GetVersion()
        {
            //Algorithm to generate version
            return C1.1.1;
        }
    }
This is what it looks like
This is how my versioning is : C1.1.1
C1 is the prefix
 public void Process(Variant model)
Indicates I am executing 1 Variant
 
What do you need this versioning for ?
 
There can be lots of variants in my system with different configuration
Once this variants are executed,I display versioning to user
C1.1.1 - Reads aas number of times variants is executed inside particular category
 
So is it correct to say that you're merging a few objects into one object thus creating a new version of it ?
I mean, what exactly changes ? The model itself /
 
12:07 PM
Versioning is just a metadata information associated with variant and category entity
C1 - Variant1
C2 - Variant2
...
CN - VariantN
C1 represent Category 1
 
Typically, database model is just a Dto object with zero or little behavior
What is the object that contains method Transform ?
 
C1.1.1 can be desribe as

C1 - Category name

1 - number of times Variants has been executed for Category C1

1 - Its an internal version of Variant
 
Could you share a bit more of your code ?
 
Yeah sure wait
 
room mode changed to Gallery: anyone may enter, but only approved users can talk
Could you write smth ?
 
private void Transform(Variant model)
{
  for (int counter = 0; counter < model.Subvariants.Count - 1; counter++)
            {
                var left = model.Subvariants[counter];
                var right = model.Subvariants[counter + 1];
                using (var processor = new AggregateTranformationProcessor())
                {
                    for (int i = 0; i < 2; i++)
                    {
                        if (i == 0)
                        {
                            processor.Start(left);
 
What ORM you use ? Entity FW ?
 
No ado.net
 
Ah, I see :-)
 
Each of the subvariant object contains connection string and sql query through which i open connection,execute sql query,pull data and then execute transformation logic on data,Save it
 
12:16 PM
Is it your working or pet project ?
 
Working Project
Hehe :)
 
Shit!
Ok, let me think a moment
 
After this transformation process,I show this data on website to user basically execution results of transformation process
 
Btw an advice - this is what you should start your next question with ;-)
Eg "I am using ADO.NET and need to blah blah"
 
But explaining everything makes my question very big and less chances of getting an answer
 
12:18 PM
There is a number of problems with this approach.
I mean when 'model saves itself to DB, has some business logics' etc
 
Approach or my current code design?
My whole transformation process is proper
Actually Versioning is created for both of my derived types ( AggregateCalculator and AdditionCalculator)
 
The architecture, usually there is a Repository object that works with db and ModelConverter object that converts model or does some other manipulations and model is just a DTO object with data
 
Hence I have taken common code(Versioning) in VariantProcessor so that it can be use by both the derived types
But this is a very small library which has only this transformation and versioning part
My project is big which has different things where I am using EF
but for this task I have used ado.net because it involved storing data in 4-5 tables thats it
 
ADO.NET is an outdated technology that I'd never suggest to use. Dapper is much better and is very fast. (StackOverflow's DAL was written based on it)
I'm looking into your code on stackexchange
 
I have asked couple of question with regards to this problem
This question contains entire code
 
12:29 PM
It returns 404
 
But I am able to open
Is it because it has been deleted ?
 
One sec brb
 
Yeah sure sir :)
 
Don't call me sir :)
 
but you are very senior to me
 
12:31 PM
 
On your profile its also written "Sr. Software Engineer " :)
public class Variant
    {
        public int VariantId { get; set; }
        public int CategoryId { get; set; }
    }

    interface IEntityVersion
    {
        string CategoryIds { get; }
        string GetVersion();
    }

    public class EntityVersion : IEntityVersion
    {
        private string _categoryIds = "100,101,102" ;
        public string  CategoryIds => _categoryIds;
        public string GetVersion()
        {
            //Algorithm to generate version
            return C1.1.1;
I have pasted all the code from that question
Probably improving this part :
  private readonly IEntityVersion _entityVersion = new EntityVersion();
Now instead of this,I am composing its behaviour using Func delegate using Lazy class as you have seen
 
Sr = senior. I'll remove it now - it doesn't matter
 
but your rep is also good on SO hence you are entitle to be call as sir :)
 
You are flattering me
 
But I really like people on SO
you guys are really really good technically
Hence my name :)
 
12:42 PM
I'd probably create ONE :))) object to do all except storing data
You don't seem to need all this chain of inheritance etc etc
For instance what do you need IVariantProcessor for ?
 
It exposed 2 methodds to client
So I always works with abstraction
 void Process(Variant model);
This methods stores data and doesnt returns anything
StatisticsModel Process(List<Subvariants> subvariants);
This method returns data to client
So its up to client which method they want to use
Derived types(AggregateCalculator and AdditionCalculator) have to implement both of this contract
 
Btw overabstraction - is another anti-pattern same as ctor over-injection
 
bdw 2nd method returns those data which i save in my first method
 
Btw where r u from ?
 
basically 1st method is consumed by windows service and 2nd method is consumed by mvc client to show immediate result on website
I am from Canada
 
12:51 PM
List<Subvariants> what is Subvariants ?
(it's missing in the code sample that you've sent
 
public class Variant
{
    public int Id { get; set; }
    public string Name { get; set; }
    public List<Subvariants> Subvariants { get; set; }
}

public class Subvariants
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string ConnectionString { get; set; }
    public string SqlQuery { get; set; }
}'
 
thanks
Ok, let me outline a few things:
1. There is no reason for DTO model to inherit from interface (EntityVersion : IEntityVersion) unless you have a few DTO models that are implementing it.
 
public StatisticsModel Process(List<Subvariants> model)
    {
        var statisticsModel = new StatisticsModel();
        var aggregateStats = new List<AggregateStatistics>();
        try
        {
            for (int counter = 0; counter < model.Count - 1; counter++)
            {
                var left = model[counter];
                var right = model[counter + 1];
                using (var processor = new AggregateTranformationProcessor())
                {
                    for (int i = 0; i < 2; i++)
public class StatisticsModel
{
    public string Name { get; set; }
    public string ErrorMessage { get; set; }
    public bool Success { get; set; }
    public List<AggregateStatistics> AggregateStats { get; set; }
    public List<AdditionStats> AdditionStats { get; set; }
}
 
Sorry I gtg now but I'll be back in 20 mins
You made a few good things there but I still think the code is a bit over-complicated. In the mean time check the design pattern: dofactory.com/net/strategy-design-pattern
 
Yeah sure sir
Thank you so much for the time :)
Appreciated :)
 
1:03 PM
Strategy design pattern might be another over-complicated but neat solution here
Hey, we're not finished here
 
But as you can here both the methods have same code but the only difference is that 1 method returns void(because it saves everything in database and consumed by windows service) and 2nd method returns model and consumed by mvc aplication to show results on website
When you are free to discuss you can ping me :)
 
1:48 PM
Hi again. So is this code working as expected ?
 
Yes my code is working fine
but seems like lots of problem with designing aspect
as mention by that user : Panagiotis Kanavos
 
Lol, he is fond of criticizing people
 
Don't pay to much attention, he used to criticize me a lot when I had smth like 1k and now he is still doing that but not to often.
to - too
 
but sometimes his ideas are great and worth considering
 
1:55 PM
Anyone can generate a good idea or two provided that he answered/commented enough questions
 
Yeah thats true
Anyways did you see my second method
having almost identical code w.r.t first method
 
Which method (what's the name) ?
 
public StatisticsModel Process(List<Subvariants> model)
    {
        var statisticsModel = new StatisticsModel();
        var aggregateStats = new List<AggregateStatistics>();
        try
        {
            for (int counter = 0; counter < model.Count - 1; counter++)
            {
                var left = model[counter];
                var right = model[counter + 1];
                using (var processor = new AggregateTranformationProcessor())
                {
                    for (int i = 0; i < 2; i++)
public class StatisticsModel
{
    public string Name { get; set; }
    public string ErrorMessage { get; set; }
    public bool Success { get; set; }
    public List<AggregateStatistics> AggregateStats { get; set; }
    public List<AdditionStats> AdditionStats { get; set; }
}
 
Let's take the 'for' loop for example
Isn't it more logical to do it without a loop ? (provided that you have only two iterations)
 
Like how ?
Subvariants is a list
 
2:02 PM
what kind of //prepare aggregate calculator model for left
What kind of business logics are there ?
I'm talking about the inner for loop: (int i = 0; i < 2; i++)
 
aggregateStats.Add(new AggregateStatistics
{
      //properties
});
//prepare aggregate calculator model for left
 
Wait
 
if (counter == 0)
{
   aggregateStats.Add(new AggregateStatistics
   {
      //populate properties with result from processor object
   });
}
This is the processor object which spits out the result :
using (var processor = new AggregateTranformationProcessor())
but this is only for 2nd method because we returns StatisticsModel thats why
 
Ok, I'll try to refactor it a bit for you
 
Can we start with some design because refactoring only this part will add something else
Ok lets say If you have this then from where you will start ?
 
2:18 PM
From the beginning :)
Architecture and design...
I'd draw it on a piece of paper first
 
Do you have any architecture or design in your mind ?
I would like to understand this process
Like how to start
I am very bad at this
 
Could you write on paper schema of what is doing what ?
A sketch :)
 
Can i write definition here of which method does what ?
 
No, it's not about methods :)
 
2:20 PM
It's about business task, requirements, what we got in database etc
 
Actually it would take a long long discussion and time if I will talk about transform method
So everything till var processor = new AggregateTranformationProcessor() is good
AggregateTranformationProcessor class returns some properties containing tranformation execution results
 
Do you know what is an XY problem ?
 
The XY problem is a communication problem encountered in help desk and similar situations in which the real issue, X, of the person asking for help is obscured, because instead of asking directly about issue X, they ask how to solve a secondary issue, Y, which they believe will allow them to resolve issue X. However, resolving issue Y often does not resolve issue X, or is a poor way to resolve it, and the obscuring of the real issue and the introduction of the potentially strange secondary issue can lead to the person trying to help having unnecessary difficulties in communication and offering...
 
Got it.Do you want to see code inside AggregateTranformationProcessor ?
 
2:24 PM
I want to see what we have got in the beginning and your vision of the problem and its solution
First of all. Explain in very simple words what problem are you solving now
 
Actually I am trying to simplify my code design.Thats it.My code is working fine i.e it is doing what it is suppose to doo
 
And what your database contains (relevant part of it in general words, I don't need to know real details)
 
But I feel like theres alot of room of impreovement in my code
 
And what it supposed to do ?
 
Those 2 steps : 1)Tranformation 2)Versioning
 
2:27 PM
What kind of transformation. It takes a few objects and merges into one ?
Or something else
 
Database contains tables and this tables contains data.Now user submits database connection string,sql query in some specific form in order for our transformation to work
 
Where does it save versions ?
So user is allowed to execute SQL queries directly ?
 
So we pull data and perform tranformation.For eg :If table contains data like null then we replace it with some menaing full data for instance 0
So this is what we do
User cannot directly
 
What does he passes in SqlQuery ?
 
User(Client) call through IVariantProcessor interface
Sqlquery like : select field1,field 2 from table1
My library supports only relational database that i execute using Ado.net and read it using data reader
All the queries that user submits are executed using ado.net data reader
 
2:31 PM
Ok, thank you very much, now I understand why we have SqlQuery field and some other things
So say I am some user that uses your web client that in turn sends a request to ASP.NET MVC controller to update few things in database (transform) for which I provide connection string and a query. What happens next ?
Now we're getting closer to what I wanted to hear from the beginning
 
internal class AggregateTranformationProcessor : IDisposable
{
    public void Start(Subvariants model)
    {
       var cn  = CreateDbConnection(model.ConnectionString);
       using (var cmd = cn.CreateCommand())
            {
                cmd.CommandText = sql;
                cn.Open();
                using (var dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
                {
			while (dr.Read())
                        {
                           //perform transformation on each data
 
Btw, which version of .Net are you working with ?
 
then this start method is called which does transformation on each record and based on that store some statistics inside database or returns it depending on which method client has called of IVariantProcessor
.Net framework 4.5
When it will be mvc application,its gonna be this method :
 StatisticsModel Process(List<Subvariants> subvariants);
because other method is consumed by Windows service and it stores results in database and later on it is also showing execution statistics on mvc website only
Basically both method have same transfformation logic but 1 is immediately showing result(which we show as preview) and other 1 is storing results in database to see N number of time so that user doesnt have to run transformation again and again for that Variant
 
I don't think that using ADO.NET you can produce quality code that follows SOLID principles, uses dependency injection (with no strong coupling) etc.
 
But for this small library,i think it will do
As you can see there is only 2 things happening here
 
2:43 PM
But I'd try anyway. What did Panagiotis Kanavos say ?
 
He said everything in comment
This is what his last comment say :
you haven't done any of that then, in fact the opposite is true. Instead of injecting the version, you're creating it inside the class. The classes have to manage data access themselves and even have to know the absolute path to a configuration string, which is definitely not their concern. Right now, you'd have to modify the internals of those classes to change even the connection string name
 
Yes this is what I meant by breaking SOLID principles
Single Responsibility is the first principle
 
1 more thing i would like to mention is that I have AdditionCalculator as well which used AdditionTranformationProcessor
but it is just using AdditionStats class and AdditionTranformationProcessor class
and only different Transformation logic
everything else is same that for loop part
 
The real problem is that you're not really understanding what you're doing. (I hope it doesn't sound rude)
 
No it doesnt
This is what i want to learn and understand
 
2:51 PM
I wish we could do something like this -> we create a NEW app with shortest code possible to reproduce this problem (for which you've written your solution) and then work on a NEW solution.
 
But before that we need to land on some design
Isnt it ?
 
For problem ? no. For new solution - yes
 
Ok we can start with new solution
Is there anything i can do here?
 
For your problem we need to have a few databases with a few tables in each, an MVC project with one API that accepts requests and viewModels that we'll send to this requests. Acceptance criteria: We have the app, user can send http request using Postman/Swagger and.... Nothing is happening
 
but we can also do with 1 console applicatin ,1 class library and having reference of that class library in console application
 
2:55 PM
And then we start working on this 'nothing' by first planing our architecture and then adding business logics (code) that will do the same thing as what your code is doing now but (hopefully) in a graceful way
What class library ?
 
All this logic is wrapped inside class library
 
We wan't to make it as realistic as possible that's why I proposed MVC proj
*want
 
and mvc application is having reference to this library
Mvc application just calling method of this class library
 
This is optional because it's a test application nothing more
Later you'll use the code from it in your real solution
 
 public class VariantFactory
    {
        public IVariantProcessor GetVariantByType(int type)
        {
            switch (type)
            {
                case (int)VariantTypes.AggregateCalculator:
                    return new AggregateCalculator();
                case (int)VariantTypes.AdditionCalculator:
                    return new AdditionCalculator();
            }
            throw new Exception("Unknown type.");
        }
    }
 
3:00 PM
Let me create an app and put it into github somewhere the only problem is to create database but for that we can use in memory collections.
 
but we dont need database at all.You can consider this class :
internal class AggregateTranformationProcessor : IDisposable
{
    public void Start(Subvariants model)
    {
       var cn  = CreateDbConnection(model.ConnectionString);
       using (var cmd = cn.CreateCommand())
            {
                cmd.CommandText = sql;
                cn.Open();
                using (var dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
                {
			while (dr.Read())
                        {
                           //perform transformation on each data
 
Why are you posting this code ?
We'll most likely write a new code for this
 
Umm okay :)
 
3:13 PM
Send me the model for uhser request please
user request
 
3:25 PM
I can't find it here in messages
Lol
 
For which method
1st or 2nd?
 
Shit, I thought you've left the room
And then I thought to myself "that was extremely rude"
I've found this model and now uploading repository to somewhere
 
Not at all sir.Infact i am very thankful to you for helping me up to this level
How does this much help in nowadays when people are so busy :)
That is why I love stackoverflow :)
 
Do you have a github or bitbucket account ?
Download the proj, start it and navigate to: localhost:58909/swagger/ui/index#!/Home/Home_Transform
 
3:48 PM
Well i dont have git account but let me see source code :)
In which file code related to my problem is?
 
I'm creating a fake implementations for things like database calls etc and fake controller that should contain api that looks close to what you have in real life
 
Ok cool :)
I am here only.let me know if you need any input and once again thank you so much for your valuable time and help
Really really appreciated :)
 
I'd strongly recommend to open a free github account
Here is the link (just in case): github.com/join
 
Yeah sure sir :)
Bdw can you please delete the chat link from that question because i think nobody will be interested to dive this deep in to my problem:)
 
Sure
 
4:04 PM
Bdw can you recommend me something to improve my object oriented design skill
I am lacking alot in object oriented skill ie design a beautiful code like the way you guys do
 
Listen, I am not a super star in coding :) Not a Jon Skeet or someone from his league
But I can recommend you something that's for sure
Clone the project from here: github.com/codemagicians/TransformTest
 
4:21 PM
Yes please recommend me something then
 
I got to go soon, it's 19:18 here in Israel. Please download the project and have a look at what's there. Our goal is to have a minimal app in which we can test different solutions to your real problem. For that we need to fake all other things that we need.
Lol now it's 19:21 )
:)
 
I have seen the code but currently there is no code related to my main business logic
Sorry if i am missing something
 
Yes because that's our task - to write this code but thinking about things like architecture, best practices etc
But for that we needed to create a 'test environment' first
Go ahead and write some business logics, I'll comment on it later. Make it work
We will continue tomorrow and create an elegant solution to your problem that we'll first test on this test project and later you can transfer parts of it to your real proj
 
Yeah sure sir.once again thank you so much
Can i ping you here tomorrow or you can ping me
 
Both, and don't call me sir :)
 
4:30 PM
All right.
 
We're not in the army
 
Bdw object oriented recommendation
 
Uhhm?
 
Coding is not less than war dealing everyday with new enemy in the form of problem :)
I mean how should I improve my object oriented skill?
 
How much experience do you have ?
 
4:32 PM
Currently 4 years
And you?
 
Is it working experience or all together ?
Actually it is only 6+ years
 
Its working experience.
 
Check this: and read this article carefully
 
Do you think with this much experience, i am very bad at programming with the way my current code is?
 
The trough is that I don't really know how good you are. All I know is that there is always room for improvement
trough = truth
I'm not even sure how good I am :)
But read about SOLID principles and start using them in your real life. This will make your code look neater
gtg, bye
 
5:32 PM
Yeah for sure :)
 

  last day (16 days later) »