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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:49:56+00:00 2026-06-12T20:49:56+00:00

The program parses log files – each log file may have different kind of

  • 0

The program parses log files – each log file may have different kind of field format (fixed width, comma delimited, etc). Also each log file are mixed of several different kind of logs – each kind have different field definition). For example, the CSV log file may look like

Log file A

logType1, 10/1/2012, 12, abc
logType2, a, b, c, d, 11/1/2012
logType1, 10/2/2012, 21, def
logType2, e, f, c, d, 12/1/2012
logType3, 3.23, ....

The following is code. How many solid-principles were violated in the following code? One guy said the list of layout definition shouldn’t be mixed with the parsing log. So it at least violates SRP (Or more)? What’s the best way to refactory the structure?

// Field
public interface IField { .... }
public class Field : IField { ... common field methods, etc.... }
public class FixedWidthField : Field { }
public class CommaDelimField : Field { ... }

// Log type
public interface ILogType<out T> where T : IField { ... IEnumerable<T> Fields { get; } }
public class LogType<T> : ILogType<T> where T : IField 
{ .... 
    public LogType(..., List<T> fields) { ... Fields = fields; }
}

// File
public inteface ILogFile<out T> where T: IField { ... IEnumerable<ILogType<T>> LogTypeList { get; set; } }
public abstract class LogFile<T> : ILogFile<T> where T: IField 
{ ....
    public IEnumerable<ILogType<T>> LogTypeList { get; set; }
    public virtual string Row { get { ... } set { ...} }
    public string GetParsedFieldString() { ... }
}
public class CommaDelimLog : LogFile<CommaDelimField>
{
     public override string Row { get { ... } set { ...code to parse the line...} }
     public override string GetParsedFieldString() { ... }
}

// The following initilize code store all the layout information
public static List<ILogFile<IField>> LogFileList = new List<ILogFile<IField>>
{
    new CommaDelimLog("logFileA", ...., new List<ILogType<CommaDelimField>> {
        new LogType<CommaDelimField>("logType1", ... new List<CommaDelimField>{ .... }
        new LogType<CommaDelimField>("logType2", ... new List<CommaDelimField>{ .... }
        ....
    }),
    new CommaDelimLog("logFileB", .... a long long list

The main program get a item from the LogFileList according to the file name pattern, read the log files line by line and assign the property Row and then get the parsed string.

  • 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-06-12T20:49:57+00:00Added an answer on June 12, 2026 at 8:49 pm

    It probably violates the open-closed principle due to inheritence from LogFile for behaviour (although GetParsedFieldString is not actually virtual in the abstract base, and it’s hard to be certain without more context).

    You could instead have some kind of parser interface, which several concrete classes implement, and whenever you need a new one, you build a new one. The risk with the LogFile class is that you’ll create more subtypes, then start finding shared behaviour, then refactor into several levels of inheritence and it will become a mess where you can’t change anything without having to do heaps of testing.

    You seem to be mostly asking about the open-closed principle, based on the question’s tag, but the Dependency Inversion principle is also being violated in that your concrete classes rely directly on other concrete classes, like CommaDelimLog relying on CommaDelimField.

    With ninject, for example, you could do something like:

    Bind<IField>().To<CommaDelimField>().WhenInjectedInto<CommaDelimLog>(); 
    

    and then pass the concrete field into the log through its constructor. The different types of field have the same signature, so the CommaDelimLog class definition doesn’t need to know directly that it relies on a CommaDelimField.

    There might be other violations, but I’ll defer to others.

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

Sidebar

Related Questions

I have a program in C# WPF which analyzes certain log files. Each log
I have written a little program that parses log files of anywhere between a
I have a log file in the format below as you can see each
I'm creating a program that parses a log file for a user's name and
I'm writing a program that parses the log files of a Windows service. The
i have C++ program exporting log files as HTML table and I wanted to
I currently have a program where I am taking existing log files from a
Well, i have written a simple python program that parses HTML with HTMLParser. Here
We have a program with a main() that parses certain CLPs but does not
I have written a simple C++ shell program to parse large XML files and

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.