A Research Agent Can Leak Private Files Through Its Search Queries
A research agent can leak a private document without uploading it. It can read a detail, turn it into a web search,…
SOLID is an acronym representing a set of five design principles to make software design more understandable, flexible, and maintainable. These principles were introduced by Robert C. Martin and are widely used in object-oriented programming. Let's dive into these principles with explanations and examples using PHP:
// Violating SRP
class UserManager {
public function createUser() {
// code to create a user
}
public function logError($error) {
// code to log error
}
}
// Complying with SRP
class UserManager {
public function createUser() {
// code to create a user
}
}
class Logger {
public function logError($error) {
// code to log error
}
}
// Violating OCP
class Rectangle {
public $width;
public $height;
}
class AreaCalculator {
public function calculate($rectangle) {
return $rectangle->width * $rectangle->height;
}
}
// Complying with OCP
interface Shape {
public function area();
}
class Rectangle implements Shape {
public $width;
public $height;
public function area() {
return $this->width * $this->height;
}
}
class Circle implements Shape {
public $radius;
public function area() {
return pi() * pow($this->radius, 2);
}
}
class AreaCalculator {
public function calculate(Shape $shape) {
return $shape->area();
}
}
// Violating LSP
class Bird {
public function fly() {
// code for flying
}
}
class Penguin extends Bird {
public function fly() {
// Penguins can't fly!
throw new Exception('Can't fly');
}
}
// Complying with LSP
interface Bird {
public function move();
}
class Sparrow implements Bird {
public function move() {
// code for flying
}
}
class Penguin implements Bird {
public function move() {
// code for walking
}
}
// Violating ISP
interface Worker {
public function work();
public function eat();
}
class HumanWorker implements Worker {
public function work() {
// working
}
public function eat() {
// eating
}
}
// Complying with ISP
interface Workable {
public function work();
}
interface Eatable {
public function eat();
}
class HumanWorker implements Workable, Eatable {
public function work() {
// working
}
public function eat() {
// eating
}
}
// Violating DIP
class LightBulb {}
class Switch {
private $bulb;
public function operate(LightBulb $bulb) {
$this->bulb = $bulb;
// operate the light bulb
}
}
// Complying with DIP
interface Switchable {
public function operate();
}
class LightBulb implements Switchable {
public function operate() {
// turn on/off the light bulb
}
}
class Switch {
private $device;
public function operate(Switchable $device) {
$this->device = $device;
$this->device->operate();
}
}
Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.
Take a look at vroni.com