typescriptCopycodeinterfaceVehicle{drive(): void;stop(): void;}classCarimplementsVehicle{drive(){console.log('Car is driving...');}stop(){console.log('Car stopped.');}}classTruckimplementsVehicle{drive(){console.log('Truck is driving...');}stop(){console.log('Truck stopped.');}}classVehicleFactory{createVehicle(type:string):Vehicle{if (type ==='car') {returnnewCar();}elseif (type ==='truck') {returnnewTruck();}else{thrownewError('Invalid vehicle type.');}}}// Uso de la fƔbricaconstfactory=newVehicleFactory();constcar=factory.createVehicle('car');car.drive();// Output: Car is driving...car.stop();// Output: Car stopped.consttruck=factory.createVehicle('truck');truck.drive();// Output: Truck is driving...truck.stop();// Output: Truck stopped.