Every time I look at a visitor pattern, I wonder, why. What is the use of this thing? Especially, when I consider modularity, I just don't understand. Let's say I have different objects: Door Engine Wheel Blinker Trunk Chair (all of them are CarParts , of course) When there's a cross-cutting concern which needs to be handled, the discussion arises: do you modify all the objects (say, they need a getCustomerValue, getBuildValue, getProductionTime, getSupplier, getRequiredComponents , for example, since we're using these parts in a factory and we need those), or maybe do you want all Supplier code to be in the same spot (since else knowledge of all suppliers gets scattered around, and you'd want it in a single spot) For the last, the code would get pretty messy. it would look something like Suppliers.getSupplierOf(Carpart part) { if(part instanceOf Door) { return "supplierOne"; } if( part instanceOf Engine) { if(((...
This is a simple blog to help me remember those cool code snippets which I used. Either by copy, or by cobbling... I do not intend this to be read by people except for me and my bad mind.