Day 44 of 100: Access Modifiers and Abstract Classes
Day 44 of 100 — 100 Days of Playwright with TypeScript Challenge. Phase: TypeScript. JavaScript (Days 1-33) → TypeScript (Days 34-63) → Playwright (Days 64-96) → AI Framework Capstone (Days 97-100).
🎭 Want to master this with real projects? Join the Playwright Automation Mastery course at The Testing Academy.
public, private, protected, abstract — visibility control for framework base classes.
Contents
The Three Modifiers
class ApiClient {
public baseUrl: string; // default — everywhere
protected token: string; // this class + subclasses
private cache = new Map(); // this class only
constructor(baseUrl: string, token: string) {
this.baseUrl = baseUrl;
this.token = token;
}
}
class AdminApiClient extends ApiClient {
useToken() { return this.token; } // OK — protected
// peek() { return this.cache; } // error — private
}
🚀 Level Up Your Playwright
From locators to CI pipelines — build a production-grade Playwright + TypeScript framework step by step.
Abstract Classes
abstract class BaseApiTest {
abstract endpoint: string; // subclass MUST define
abstract validate(body: unknown): boolean; // subclass MUST implement
async run(): Promise { // shared logic
const res = await fetch(this.endpoint);
return this.validate(await res.json());
}
}
class UsersApiTest extends BaseApiTest {
endpoint = '/api/users';
validate(body: unknown) { return Array.isArray(body); }
}
// new BaseApiTest() — error: cannot instantiate abstract
Caution
- Abstract base + one level of subclass: fine for API test families
- Deep abstract chains: the Selenium-era trap — prefer fixtures (Day 76)
- Most Playwright POMs need zero inheritance
Tomorrow (Day 45): Utility types — Partial, Pick, Omit for test variants.
🎓 Master Playwright End to End
Join hundreds of SDETs building real automation frameworks. Lifetime access, hands-on projects, and a job-ready portfolio.
