Object-Oriented Programming


Michael L. Collard, Ph.D.

Department of Computer Science, The University of Akron


a particular set of information that affects the code of a computer program

  • A section of conceptual information
  • Want to identify concerns
  • Want to separate concerns

srcFacts: Concerns

Count Articles


Count Articles: Concerns

  • English-language articles
    • i.e., “the”, “a”, “an”
  • PDF content
    • e.g., a PDF contains text
  • PDF format
    • e.g., how PDF stores content

Count Articles: Separate Concerns

  • English-language articles
    • -> CountArticles.cpp
  • PDF content
    • -> PDF interface declared in pdf_reader.hpp
  • PDF format
    • -> PDF implementation in pdf_reader.cpp

Why Separate Concerns?

  • Focus on one part at a time (modularity)
  • Work with very complex formats (e.g., a PDF) or systems by only understanding the interface (usability)
    • usability, not just for end users”
  • Test separately
  • Use for other purposes (reusability)
  • Focus on fault tolerance, reliability, performance, scalability, robustness, extensibility, maintainability, security, portability

Count Articles Design

  • Does the current design of CountArticles really separate concerns?
  • CountArticles
  • Nope
  • Why?

Improve Design: Separate Concerns

What We Have

What We Want

srcFacts: Concerns

Goal: Separate srcFacts Concerns

  • srcFacts report -> srcFacts.cpp
  • Markdown -> srcFacts.cpp
  • srcML -> srcFacts.cpp
  • XML concepts -> xml_parser.hpp
  • XML parsing -> xml_parser.cpp

Overall srcFacts Project Goal

  • Get as much of the XML parsing details out of srcFacts.cpp
  • Isolate srcML to srcFacts.cpp
    • Implies no knowledge of srcML in xml_parser
    • Including no use of srcML element names in xml_parser, i.e., no “return” string comparison
  • Note: Without additional language features, unable to fully separate XML parsing from srcFacts (No, I am not just talking about classes)


  • Reuse of xml_parser for non-srcML projects
  • Test xml_parser (untestable in original state)
  • Write other source-code reports by reusing xml_parser

srcFacts Design

Adhoc Design

Improved Design

Separate XML Concerns

  • Contains all details of the XML format
  • Does not depend on srcML
  • Has no knowledge of srcML
    • Does not know that there is a srcML element “return”
    • Does not know that there is a srcML element “literal”
    • Does not know that there is a srcML attribute of “type”
  • Can be reused in other programs which access XML data

XML Events


Improved Design

What is possible with a separate XML parser?

  • Test parser in isolation
  • Time the parser
  • Replace with another XML parser
  • Write lots of source reports
  • Perform a source-code transformation:
    • E.g., convert from for to range-based for loop
  • Use for any application which needs XML parsing