[HD] EECS4302 F26 - 2026-09-17 (Thursday) - Lecture 3
Overview
Jackie Wang introduces cohesion, the Single Choice Principle, and regression testing as design checks for EECS4302 projects, then applies them to Java student classes and compiler architecture. The lecture contrasts 20 direct translations among five languages with a modular intermediate-representation approach, and previews how ANTLR 4 can generate scanners and parsers.
Key takeaways
- A class is cohesive when its fields and methods share a purpose; separate resident and nonresident rate fields in one Java Student class are a concrete sign that the class mixes responsibilities.
- The Single Choice Principle asks that a change affect the minimum necessary number of places: repeated kind checks in tuition and registration methods make adding a student category unnecessarily costly.
- Inheritance can improve both cohesion and change localization: shared tuition logic belongs in Student, while rate-specific behavior belongs in ResidentStudent and NonresidentStudent.
- Passing JUnit tests supports correctness only relative to the tests executed; as Edsger W. Dijkstra observed, testing can reveal bugs but cannot establish their absence.
- For five source and target languages, direct pairwise translation needs 20 compilers, whereas a shared-IR architecture can use five front ends and five back ends in Wang's schematic design.
- ANTLR 4 can generate a scanner and parser from token patterns and a context-free grammar, automating two key front-end stages.
Chapters
- Jackie Wang directs students to the compass icon on the lecture site for the September 15 digest and says materials are usually posted shortly after class.
- The digest includes main ideas, key terms, examples, common pitfalls, learning outcomes, suggested practice, and links to notes or recording timestamps.
- It supplements rather than reproduces lecture notes; students should return to notes and recordings for full worked examples.
- Wang says the digest is AI-assisted, based on class content, and checked through external validation and proofreading.
- Cohesion concerns whether attributes and methods within one class serve a shared purpose or unifying theme.
- A class has weak cohesion when its members divide into groups serving unrelated responsibilities.
- The Unix principle, each command should do one thing well, illustrates cohesion; commands such as ls, cd, and pwd can be combined through pipelines.
- Wang defines the Single Choice Principle (SCP) as making a change affect the minimum necessary number of places in the software.
- Duplicate logic, whether within one class or across classes and packages, is a common sign that SCP is violated.
- Helper methods can factor out repeated logic; the minimum number of changed places need not be one, but the number must be justified.
- The initial Java design represents both student types with one Student class and an integer kind field: 1 for resident and 2 for nonresident.
- The class stores courses, a course count, a resident premium rate, and a nonresident discount rate.
- Tuition calculation branches on kind to apply a premium or discount; course registration also branches to enforce different course caps.
- Every resident object carries an irrelevant discount-rate field, while every nonresident object carries an irrelevant premium-rate field.
- Because the two rate attributes serve different student categories, they do not share one purpose within the combined Student class.
- Wang uses the unused fields as a practical clue that the class responsibilities can be separated.
- The tuition and registration methods both repeat checks such as kind == 1 and kind == 2.
- Adding a third student type would require changes in multiple methods, so the implementation makes one conceptual change affect several places.
- Removing a student type would likewise require deleting repeated branches from multiple methods.
- A parent Student class holds shared course data and base tuition calculation; ResidentStudent and NonresidentStudent subclasses hold only their relevant rate.
- Each subclass overrides tuition calculation and uses super to reuse the parent's base total before applying its premium or discount.
- A new student type can be added in a new subclass, while shared tuition logic remains centralized rather than duplicated.
- The subclass design improves cohesion and supports SCP by localizing type-specific behavior.
- Test cases should cover both normal and abnormal inputs, including cases that trigger errors or exceptions.
- Passing tests establishes correctness only with respect to the tests run; the test suite acts as a limited specification.
- Wang cites Edsger W. Dijkstra's point that testing can show the presence of bugs, but cannot prove their absence.
- When model classes change, rerun all existing JUnit tests; use breakpoints and a debugger to investigate failures.
- A compiler front end transforms a source program in concrete syntax into an intermediate representation (IR), while a back end transforms that IR into an output program.
- Source and target programs are concrete syntax, such as text files; the IR is an abstract, often tree-shaped runtime structure.
- The IR can be represented by a hierarchy of classes, and optional optimization stages can operate between the front end and back end.
- For five languages (Java, C, C#, C++, and Python) direct translation requires 5 × 4 = 20 compilers when same-language translations are excluded.
- Each source language may need a separate compiler for every other target language.
- Wang uses this count to motivate sharing intermediate representations instead of building every pairwise translation independently.
- Wang proposes dividing language features into a basic procedural IR for constructs such as if statements, loops, and sequential composition.
- A second, advanced procedural IR captures pointers and pointer arithmetic; a third IR represents object-oriented features such as classes, attributes, and inheritance.
- The language-feature divisions are illustrative design choices: C lacks object-oriented features, while C++ combines procedural, pointer, and object-oriented capabilities.
- Each of the five source languages can have a front end that maps its constructs into the relevant shared IR or combination of IRs.
- Five back ends can map the shared representations into the five target languages, yielding a schematic total of 5 + 5 rather than 5 × 4 translation modules.
- Wang describes the direct approach as multiplicative and the shared-IR approach as additive, while noting that the architecture is schematic.
- Students suggest chaining compilers as another option; Wang notes that chaining may help but is not always possible.
- The scanner performs lexical analysis, checking individual tokens, for example, whether a keyword is spelled correctly.
- The parser performs syntactic analysis against a context-free grammar.
- ANTLR 4 can generate both scanner and parser code from specified regular-language patterns and grammar rules.
- The conventional compilation example maps a high-level language such as C to low-level, machine-oriented code.
- Wang plans to release Assignment 1 the following week and give students two weeks to complete it.
- The assignment involves programmatically building something related to DFA and NFA using Java.
- Relevant lecture slides will be identified to support the assignment.
Transcript excerpt
0:05 All right. So, I would like to show you guys very quickly about the lecture digest because for our Tuesday's class is actually more than just syllabus. It's actually some technical contents. Well, not strictly technical, but at least it's relevant to the course, more relevant to the content. Id like to show to you uh first of all how you can find it again and then go over with you very quickly about the document so you can really [snorts] decide how you want to use it uh for your study you know for the written test or for the exam later ultimately so again if you look at the uh lecture site and then let me just refresh it okay just to be sure okay so you can see from Tuesday's class September 15 right so everything is there um I may not actually send you like announce ment for
0:52 like every time when the lecture uh recording lecture notes or lecture digest are ready so please just check so usually should be shortly after the class maybe the next day uh early next day I'll try to uh just make make sure everything's available there so especially you can look at the compass icon here if you click on that it will be the lecture digest for lecture number two okay over here why don't we just go over very quickly about it general structure and then I'll highlight certain section to you can decide how you want to use Of course, if you got any feedback about how to improve the structure or contents of the lecture digest, do let me know. I think uh for me to maybe make some adjustment possibly during the reading week. So when we produce the new ones after reading week, we can adapt. Okay.
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Jackie Wang.