Typescript Factory Pattern without Switch or If Else

Factory pattern is a well known creator pattern. Problem with factory pattern is whenever there is a new concrete class that will be instantiate by the creator class (that have factory method), you have to add new ‘case’ in a switch or if / else.

So this violate the Open Close Principle which states open for extensions but close for modifications.

Code below using typescript, but the concept is same for other programming language.

Factory Pattern with Switch or If Else

If you want to add Square shape, we need to add another case in the factory.

The concept is the same with If Else

So I need to open my factory class every time there is a new shape to be add in.

Factory Pattern without Switch & If / Else

There are 3 main classes

1) Factory class
– it will import the shape class files in the folder /shapes
– instantiate the object based on shape type

2) Shape abstract class
– abstract method of getType()

3) Shape concrete class
– implement the getType() to tell what type is the shape e.g round
– located in /shapes folder

The concrete class Shape will implement a function to tell it is what kind of Shape.

The factory class will import all the shape file path and instantiate the object when call by user class.

How To Use It?

Impact

It requires async / await because needs to load dynamically the shape class.

This factory pattern can’t be used in a constructor.

 

 

Tangki Air Rumah Bocor? Bagaimana nak pastikan?

Baru-baru ini, tiba-tiba air mengalir dari tempat terletaknya tangki air rumah saya.

Memandangkan banyak juga air yang mengalir saya memanggil “plumber” yang saya baru kenal. Saya namakan dia plumber #1.

siling lembab air bocor dari lantai tangki air
siling lembab air bocor dari lantai tangki air
air bocor melimpah sampai ke lantai
air bocor melimpah sampai ke lantai
air bocor dari dinding tempat tangki air
air bocor dari dinding tempat tangki air

Plumber #1 – Air Tangki Bocor!

Setiap kali, ada kerosakan saya akan minta plumber atau handyman untuk tunjukkan gambar dan video benda yang rosak.

Plumber #1 mengatakan selepas check tangki air bocor dan menunjukkan video lantai penuh dengan air. Saya tanya tak nampak pun air bocor dari tangki. Dia cakap ada bila rasa pakai tangan tapi tak dapat nak ambik gambar.

Dia cakap untuk replace tangki air yang bocor RM2,500. Dia bagi murah RM2,200. Saya tanya dia kenapa tak boleh tampal.

Plumber #1 cakap kalo bocor kat bawah tampal tak tahan lama. Mula-mula saya tak nak ambil, saya nak tunggu hari Ahad je bila plumber yang saya percayai @ Rudy available untuk membuat pemeriksaan. Tetapi memandangkan air banyak jugak mengalir saya membuat keputusan untuk mengupah plumber #1. Cuma syarat saya dia keluar duit semua dulu dan dah siap saya bayar.

Saya cakap terus terang saya baru kenal dia jadi kepercayaan tu tak ada lagi.

Selepas dia balik tak lama lepas itu, dia telefon saya, tangki boleh tampal. Saya tanya dia balik, tadi cakap tak boleh tampal. Plumber #1 cakap dia ada kawan expert boleh tampal hanya RM1,000. (dalam hati saya tampal selalunya orang minta RM400 je)

Selepas dia cakap cam tu saya terus cakap cancel kerja repair saya minta second opinion. Kemudian dia cakap dia bagi RM850. Saya bertegas tak nak proceed.

Plumber #2 – Membuat Pemeriksaan & Paip yang Bocor

Plumber #2 iaitu Rudy siap ambil video dan bagitau yang paip yang bocor dan tangki air tak bocor antara buktinya panel kayu tempat duduk tangki air adalah kering.

Kesimpulan

Hati-hati bila ambil plumber baru dan tiba-tiba nak caj mahal. Lagi baik dapatkan second opinion. Biorlah lambat dari rugi beribu ringgit.

Plumber #2 – Rudy hanya kenakan bayaran RM180 sahaja vs plumber #1 RM2,200.

Alhamdulillah, saya tak kena tipu orang.

No telefon plumber #2 – Rudy

011 3310 8757

 

How To Launch XAMPP After Installation?

I installed XAMPP then after installation the XAMPP control manager appeared after that. If you restart your computer, I wonder where I can launch it because XAMPP is not appeared in LaunchPad.

Applications folder of XAMPP also has so many files.

How To Launch XAMPP?

Go to Applications -> XAMPP -> xamppfiles .

Then click on manager-osx.

Key in your password and then the XAMPP control manager will appear.

manager-osx to open xampp
manager-osx to open xampp

Epson L3150 Color Printing Problem Solution

I had color printing problem with my Epson Ecotank L3150 printer. When I print color, it became pinky only.

How To Solve Color Printing Problem on Epson L3150?

1) How To Access Head or Power Cleaning in Windows or MacOS?

MAINTENANCE CLEANING: for WINDOWS OPERATING SYSTEM

1. Go to Start Menu
2. Search control panel > Devices and printers
3. Look for the model of your printer
4. Right click on the printer then click on printing preferences.
5. Go to maintenance tab.
6. Click on head cleaning then click on START.
(Take note: Print head cleaning usually takes 3 to 5 minutes, after the print head cleaning do some test print to see if there are improvements on the print out. If still the same do the head cleaning up to 3x

If Print head cleaning didn’t work proceed to Power cleaning

Power Cleaning

1. Go to Start Menu
2. Search control panel > Devices and printers
3. Look for the model of your printer
4. Right click on the printer then click on printing preferences.
5. Go to maintenance tab.
6. Click on Power cleaning / Power ink flushing then click on START.
(Take note: Power cleaning / Power ink flushing may takes 10 to 15 minutes, after the Cleaning/Flushing, advised customer to rest the printer for 1 hour to rest, after an hour do some test print. If still the same, advised customer to bring the unit down to our ASP for service or Create Job request if unit is eligible for Onsite support)”

MAINTENANCE CLEANING: for MACINTOSH OPERATING SYSTEM

1. Go to System Preference
2. Search Printers & Scanners
3. Look for the model of your printer
4. Select on the printer name then click on options and supplies.
5. Choose utilities then open printer utilities.
6. Click on head cleaning then click on START.

(Take note: Print head cleaning usually takes 3 to 5 minutes, after the print head cleaning do some test print to see if there are improvements on the print out. If still the same do the head cleaning up to 3x

If Print head cleaning didn’t work proceed to Power cleaning

Power Cleaning

1. Go to System Preference
2. Search Printers & Scanners
3. Look for the model of your printer
4. Select on the printer name then click on options and supplies.
5. Choose utilities then open printer utilities.
6. Click on Power cleaning / Power ink flushing then click on START.
Please note: Rest the printer for at least an hour before doing another test print to check the quality of the printer. If print out problem still persist, contact the following service center for the unit evaluation.

2) Do the Head Cleaning.

If the head cleaning doesn’t work then only do Power Cleaning.

epson L3150 - head cleaning
epson L3150 – head cleaning

In my case the head cleaning, didn’t solve the color printing problem.

3) Power Cleaning

Choose the Power Cleaning. Epson advises to do it once in 12 hours as it consumes much ink. In my case, it used 5-10% of my black ink.

Epson L3150 power cleaning to solve the color printing problem
Epson L3150 power cleaning to solve the color printing problem
epson L3150 power cleaning warning notice
epson L3150 power cleaning warning notice
epson L3150 - my power cleaning is complete
epson L3150 – my power cleaning is complete

 

The Nice Color Printing

After I did the Power Cleaning, now my Epson prints the color correctly.

How To Install PHP MySQL & Apache on MacOS Ventura on MacBook Pro M1

In my previous post, I was unable to install PHP & MySQL. This time after 2 years, I tried again but still fail, so I decided to use XAMPP to install PHP & MySQL and Apache on MacOS Ventura and it works!

But I had to disable default installed apache2 and change MySQL default port at XAMPP before MySQL and Apache2 can run on XAMPP.

How To Install PHP, MySQL & Apache using XAMPP

1. Download and install XAMPP

Mount the xampp dmg and run it. If you face unknown publish then do Control + Click on the XAMPP installer then run it again.

2. Follow the step by step instruction in installing XAMPP

Just follow the instructions.

3. Run the servers

If you unable to run the MySQL & Apache web server than follow below solution.

xampp macos ventura - mysql and apache webserver unable to start
xampp macos ventura – mysql and apache webserver unable to start

If you can run MySQL change it default ports. I use 3316 instead of default 3306.

xampp macos ventura - change the default port to 3316
xampp macos ventura – change the default port to 3316

I tried to stop mysql service but MacOS informed no MySQL service was running. Only by changing MySQL default port it works.

xampp macos ventura - mysql not running
xampp macos ventura – mysql not running

If you can’t run the apache2 server, stop default apache2 server by typing at the terminal.

Then run again Apache Web Server at XAMPP.

xamp macos ventura - apache webserver now running
xamp macos ventura – apache webserver now running

4. Test PHP & MySQL by accessing PhpMyAdmin

If you can access phpMyAdmin and create table or user from phpMyAdmin then your XAMPP installation works!

xampp macos ventura - access localhost and click phpmyadmin
xampp macos ventura – access localhost and click phpmyadmin
xamp macos ventura - successful installed php and mysql now can access phpmyadmin
xamp macos ventura – successful installed php and mysql now can access phpmyadmin