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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:07:26+00:00 2026-05-10T20:07:26+00:00

I take care of critical app in my project. It does stuff related to

  • 0

I take care of critical app in my project. It does stuff related to parsing business msgs (legacy standard), processing them and then storing some results in a DB (another apps picks that up). After more then a year of my work (I’ve other apps to look after as well) the app is finally stable. I’ve introduced strict TDD policy and I have 20% unit test coverage (thank you Michael Feathers for your book!), most of it in critical parts. I have some white-box Fitness tests as well (whole business scenarios are covered there). I feel that I cannot further refactor this app and I’m safe to play hard with it. It’s designed so badly, I want to rewrite it. App itself is around 20k of challenging legacy C/C++ code. There were other dependencies but I manged to decouple most of them.


All I have is Sun C++ compiler, cppunitlite, STLPort and Boost. Please do not suggest other technologies (no XML, Java etc) as this is not the option in my organization. I’d like to do it with modern C++ (perhaps play with metaprogramming…), TDD from start to the end.

There are about 30 types of msgs I need to parse. Each of them is composed of 3-10 lines, most of them are pretty similar. This is root of all evil -> lots of code duplication. Each msgs has a class describing how it should be parsed. Take a look at the main inheritance tree:

                             MSG_A                     MSG_B                             /     \                   /     \                     MSG_A_NEW   MSG_A_CNL      MSG_B_NEW   MSG_B_CNL 

Both trees goes much deeper. There are very small differences between MSG_A_NEW and MSG_B_NEW. It should be handled by single class that could be injected with some small customization.

My initial plan it to have one generic msg class that will be customized. Some entity (builder… ?) will take a look at the msgs and initialize proper object that will be able to parse the msg. Another entity will be able to discover what line is it and this info will be used by builder. I’m planning to write several parsers that are responsible for parsing just one specific line. This will allow me to reuse it in parsing different msgs.

There are several challenges that I struggle to solve in an elegant and extensible way. Each type of msg:

has min and max number if lines – has some must-have lines – has some optional lines – certain lines must be at certain places (i.e. date cannot be before msg type), order matters

I need to be able to validate format of the msgs.


I’m not sure if I explained the design challenge here good enough. My design experience is very limited. I’ve been bug-fixing for a while now and finally I will have a change to do some fun codding 🙂

What high-level advice do you have for that? Which design patterns can you identify in this description? Main design constraint is maintainability and extensibility with performance at the bottom (we have other bottlenecks anyway…).

  • 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. 2026-05-10T20:07:26+00:00Added an answer on May 10, 2026 at 8:07 pm

    I would advise you not to inherit your specific message handling classes from base classes that contain the common code like this:

           CommonHandler             ^                                   ^             |                                   |  = inheritance        MsgAHandler         ^       ^         |       | ANewHandler     ACnlHandler 

    This approach suffers from bad reusability: for example if you want to handle some kind of message that needs to do things from A_NEW and A_CNL, you would end up with multiple inheritance rather quickly.

    Instead I would choose a class containing the common code, that makes calls to an interface to customize that common code. Something like this:

    BasicHandler <>--- IMsgHandler ------------\ 1 1 ^ ^ ^ ^ * | ^ | | | | | | = inheritance MsgAHandler | | ANewHandler 1 | ACnlHandler HandlerContainer <>-/ <>- = containment

    The HandlerContainer class can be used to group the behaviour of other handlers together.

    This pattern is called 'Composite', if I'm not mistaken. And to create the correct instances of the handlers, you will of course need some kind of factory.

    Good luck!

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

Sidebar

Ask A Question

Stats

  • Questions 66k
  • Answers 66k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You could create a Dictionary<DropDownType, DropDownDtoDelegate> with each entry containing… May 11, 2026 at 11:28 am
  • added an answer I'd strongly recommend switching to the DOM functions over SimpleXML.… May 11, 2026 at 11:28 am
  • added an answer I don't see any point in using a weak reference.… May 11, 2026 at 11:28 am

Related Questions

I take care of critical app in my project. It does stuff related to
On a server I have to take care of, errors from a vhost do
How do I take a set of polygons which contain arbitrary values and create
How can I take the string foo[]=1&foo[]=5&foo[]=2 and return a collection with the values
What steps do I take? Any gotchas to be aware of or tips to
How do I take a string in Perl and split it up into an
How do I take a jar file that I have and add it to
When I am creating a new database table, what factors should I take into
http://en.wikipedia.org/wiki/Diamond_problem I know what it means, but what steps can I take to avoid
In .NET (VB), how can I take all of the items in one collection,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.