design patterns - I need to ask about the object class, but it's a bad practice. Alternatives for this case? -


i'm having trouble extending application. attendance record system. each employee records attendance card has qr code. want add fingerprint recognition, , there no problem until asked 2 forms of identification must coexist in system. thus, system must able sense qrs of employee, fingerprint.

i have following classes:

the way fix in qridstrategy via .equalsto(id) method is:

equalsto(id){   if (id == iskindof (qridstrategy))     if (this.getemployeeid () == id.getemployeeid ())       return true;    return false; } 

but understand asking class of object bad practice , don't want that. how can fix it?

i thought of visitor pattern, still have same problem of comparing 2 classes not of same type (because system scan of 2 types)

enter image description here

maybe first diagram shows i'm going say, comes down polymorphism.

create abstract class (e.g. identificationstrategy method equlasto()). derive 2 classes: qrstrategy , fingerprintstrategy identificationstrategy , implement equlasto() method in each of them.

now, there place in code know whether create instance of qrstrategy or fingerprintstrategy. assign instance of object variable of identificationstrategy type (e.g. let's name 'foo' ). when call equlasto() method on 'foo', don't care object type more.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -