Using a Visitor Pattern to apply the Law of Demeter?

I don't understand how to use Law of Demeter (LoD) with hierarchical classes and the Visitor Pattern.
The hierarchy of classes is for example (with relationships): Article [m:m] Supplier [m:1] Address.
If I want to set the address, I would normally have to code something like: article.getSupplier(4711).getAddress().setStreet("G.W. Bush Street 1"); // ironic
I don't know much of LoD, but I think this example violates it heavily.
How does the solution for this example look like with respecting LoD by using a Visitor Pattern?
And what do you think about it?

TO use the visitor pattern all the visited objects
must have a common interface, and I don't see one
between Supplier, Address and Article.I think they don't need a common interface. Look at the sample code:
package test;
class VisitorPattern {
     public static void main(String[] args) {
          Cheese cheese1 = new Wensleydale();
          Cheese cheese2 = new Gouda();
          Cheese cheese3 = new Brie();
          Visitor v = new VisitorImpl();
          cheese1.accept(v);
          cheese2.accept(v);
          cheese3.accept(v);
interface Visitor {
     void visit(Wensleydale w);
     void visit(Gouda g);
     void visit(Brie b);
class VisitorImpl implements Visitor {
     public void visit(Wensleydale w) {
          System.out.println(w.wensleydaleName());
     public void visit(Gouda g) {
          System.out.println(g.goudaName());
     public void visit(Brie b) {
          System.out.println(b.brieName());
interface Cheese {
     void accept(Visitor v);
abstract class BaseCheese implements Cheese {
class Wensleydale extends BaseCheese {
     String wensleydaleName() {
          return "This is wensleydale";
     public void accept(Visitor v) {
          v.visit(this);
class Gouda extends BaseCheese {
     String goudaName() {
          return "This is gouda";
     public void accept(Visitor v) {
          v.visit(this);
class Brie extends BaseCheese {
     String brieName() {
          return "This is brie";
     public void accept(Visitor v) {
          v.visit(this);

Similar Messages

  • Passing arguments in Visitor Pattern

    Does anybody have a nice solution to passing arguments in Visitor pattern?
    The Visitor pattern is used to process an object structure (such as an abstract syntax tree) in many different ways without cluttering definitions of the objects with methods needed for all different kinds of processing. Instead, each object has only one method, "void accept(Visitor v)". The method calls back a method in the Visitor that is appropriate for the object. Different kinds of processing use different Visitors, each with its own set of object-processing methods.
    My problem is that I need to pass arguments or receive results from the object-processing methods, different for different kinds of processing.
    One solution is to have many "accept" methods with different signatures. This beats the idea that we do not need to modify definitions of the objects if we want to introduce new kind of processing.
    Another is to provide "accept" with an Object result and a sufficient number of Object arguments, to be used as necessary by different Visitors. It results in clumsy and unreadable code. Detestable.
    Alternatively, one could provide fields in the objects to pass the information when needed. This frees the invocations of "accept" from dummy arguments/results, but does not seem nice.
    One can also forget all about Visitor pattern, and let the processing method test the object class using "instanceof" and call the right method. But this is a pure blasphemy against everything called OO.
    Is there any better way that I am too blind to see?

    Sounds to me like you've got a case of combining different concerns into the same design. I think you're looking at multiple problems, all of which require you to process an object structure.
    I'd make a general framework for processing my structure, and then use a specific interface for each problem. I would avoid re-using the Visitor pattern for multiple concerns as it leads to exactly the problems you're facing.
    If you're dead-set on using the Visitor; how about having a mediator or adapter between the visited class and the Visitor that deals with the specifics of each invocation?
    Personally, I think the Visitor pattern violates basic encapsulation and polymorphism - but that's just my opinion. I try to avoid using it unless I'm stuck with NO other solution.
    Good luck.

  • Using Shading Dictionary to perform shading in pdf,before that the shading dictionary call from Pattern Dictionary.In the Pattern Dictionary there is an Matrix based on the matrix value  location the shading operatihow the axial shading is preserve in pdf

    using Shading Dictionary to perform shading in pdf,before that the shading dictionary call from Pattern Dictionary.In the Pattern Dictionary there is an Matrix based on the matrix value  location the shading operation is perform,So i dont know how to calculate value of pattern Dictionary matrix value.
    10 0 obj
    << /Type /Pattern
    /PatternType 2
    /Shading 11 0 R
    /Matrix [1.00 .00 .00 1.00 54.00 53.00]  // the matrix value how to calculate
    >>
    11 0 obj
    <<
    /ColorSpace /DeviceRGB
    /Function 12 0 R
    /ShadingType 2
    /Coords [109.2726 69.00 109.2726 .00]
    /Extend [true true]
    >>
    12 0 obj
    <<
    /FunctionType 0
    /Domain [.00 1.00]
    /Range [.00 1.00 .00 1.00 .00 1.00]
    /Size [1002]
    /BitsPerSample 8
    /Length 3006
    >>
    stream
    here is an stream of colors
    endstream
    endobj
    Can anybody help me please.
    Regards, Sasi kumar sekar.

    Hi, Sasi -
    The Matrix maps coordinates in your shading dictionary into User Space. That is, the Matrix entry in the Pattern dictionary specifies a coordinate transformation that will be applied to coordinates specified in the shading dictionary.
    To take your example, you have an axial shading extending from (rounding off) 109,69 to 109,0.  Your Pattern dictionary specifies the Matrix
    [ 1  0  0  1  54  53 ]
    This transformation matrix corresponds to a scale of 1,1 (that is, no change in scale) and a translation of 54,53. Thus, the actual endpoints for the axial shading will be the User Space positions 163,122 and 163,53 (assuming I’ve added correctly).
    As to what values to use for your Matrix, it depends on how you’ve set up your Shading dictionary. If the coordinates you’ve specified are actually where you want the gradient to go, then just use an identity matrix
    [ 1  0  0  1  0  0 ]
    By the way, are you sure that the Pattern dictionary includes a Matrix entry? I seem to remember (it's been a while since I've looked at Patterns) that the matrix is supplied as an argument to the makepattern operator:
    <<patternDict>> [ 1 0 0 1 0 0 ] makepattern
    Hope that helps.
    - John Deubert
      Acumen Training
      PostScript and PDF
      Training & Consulting

  • "Not using a pattern recognized by the GSA table invalidation mechanism" warning (many-to-many items relationships)

    Hello.
    I'm getting such warnings on server startup:
    12:57:33,241 WARN  [StoreRepository] Warning - table: store_user appears in item descriptors: store and user but not using a pattern recognized by the GSA table invalidation mechanism.  Cached values from this table will not be updated when user's properties are modified.  These properties for this table are: [storeUsers]
    12:57:33,241 WARN  [StoreRepository] Missing a src id property in item-descriptor user's table named store_user whose column-names are store_id
    12:57:33,242 WARN  [StoreRepository] Missing a dst id property in item-descriptor store's table named store_user whose column-names are user_id
    12:57:33,242 WARN  [StoreRepository] Missing a dst multi property in item-descriptor store's table named store_user whose column-name is store_id
    12:57:33,242 WARN  [StoreRepository] Warning - table: store_user appears in item descriptors: user and store but not using a pattern recognized by the GSA table invalidation mechanism.  Cached values from this table will not be updated when store's properties are modified.  These properties for this table are: [userStores]
    12:57:33,243 WARN  [StoreRepository] Missing a src id property in item-descriptor store's table named store_user whose column-names are user_id
    12:57:33,243 WARN  [StoreRepository] Missing a dst id property in item-descriptor user's table named store_user whose column-names are store_id
    12:57:33,243 WARN  [StoreRepository] Missing a dst multi property in item-descriptor user's table named store_user whose column-name is user_id
    Here's repository definition file:
    <item-descriptor name="user" id-space-name="user" display-name="User" display-property="name">
      <table name="user_tbl" type="primary" id-column-name="user_id">
           <property name="id" column-name="user_id" data-type="string" display-name="Id">
                <attribute name="uiwritable" value="false" />
                <attribute name="propertySortPriority" value="-1" />
           </property>
           <property name="name" column-name="user_name" data-type="string" display-name="Name">
                <attribute name="propertySortPriority" value="-1" />
           </property>
      </table>
      <table name="store_user" type="multi" id-column-names="user_id" multi-column-name="store_id">
           <property name="userStores" display-name="User Stores" data-type="map" column-names="email" component-data-type="string">
                <attribute name="propertySortPriority" value="-1" />
                <attribute name="uiwritable" value="false" />
           </property>
      </table>
    </item-descriptor>
    <item-descriptor name="store" id-space-name="store" display-name="Store" display-property="name">
      <table name="store_tbl" type="primary" id-column-name="store_id">
           <property name="id" column-name="store_id" data-type="string" display-name="Id">
                <attribute name="uiwritable" value="false" />
                <attribute name="propertySortPriority" value="-1" />
           </property>
           <property name="name" column-name="store_name" data-type="string" display-name="Name">
                <attribute name="propertySortPriority" value="-1" />
           </property>
      </table>
      <table name="store_user" type="multi" id-column-names="store_id" multi-column-name="user_id">
           <property name="userStores" display-name="User Stores" data-type="map" column-names="email" component-data-type="string">
                <attribute name="propertySortPriority" value="-1" />
                <attribute name="uiwritable" value="false" />
           </property>
      </table>
    </item-descriptor>
    I'll appreciate it, if someone tell me what's wrong with my definition.
    Thank you in advance,
    Jurii.

    Hi Jurii,
    You are right about ATG docs do not have info about M-M that can fit into your requirement. So we have to give it a try :-)
    Please try with the below definition to see it it works.
    user_tbl and store_tbl - no changes
    store_user table has three columns - user_id, store_id and email
    <item-descriptor name="user" id-space-name="user" display-name="User" display-property="name">
      <table name="user_tbl" type="primary" id-column-name="user_id">
           <property name="id" column-name="user_id" data-type="string" display-name="Id">
                <attribute name="uiwritable" value="false" />
                <attribute name="propertySortPriority" value="-1" />
           </property>
           <property name="name" column-name="user_name" data-type="string" display-name="Name">
                <attribute name="propertySortPriority" value="-1" />
           </property>
      </table>
      <table name="store_user" type="multi" id-column-names="user_id">
           <property name="store" display-name="Stores" data-type="set" column-names="store_id" component-item-type="store"/>
        <property name="email" display-name="User Store Email" data-type="set" column-names="email" component-data-type="string"/>
      </table>
    </item-descriptor>
    <item-descriptor name="store" id-space-name="store" display-name="Store" display-property="name">
      <table name="store_tbl" type="primary" id-column-name="store_id">
           <property name="id" column-name="store_id" data-type="string" display-name="Id">
                <attribute name="uiwritable" value="false" />
                <attribute name="propertySortPriority" value="-1" />
           </property>
           <property name="name" column-name="store_name" data-type="string" display-name="Name">
                <attribute name="propertySortPriority" value="-1" />
           </property>
      </table>
      <table name="store_user" type="multi" id-column-names="store_id">
           <property name="user" display-name="Users" data-type="set" column-names="user_id" component-item-type="user"/>
        <property name="email" display-name="User Store Email" data-type="set" column-names="email" component-data-type="string"/>
      </table>
    </item-descriptor>
    Thanks,
    Gopinath Ramasamy

  • Trouble using a pattern match in the GO URL when the value starts with %

    Hi guys,
    We are trying to use a Go URL as follows:
    [http://hostname.com:9704/analytics/saw.dll?Go&Path=/users/administrator/Test/TestReport&Action=Navigate&col1=TestReport.SUBJECT&op1=like&val1="%25D8D8%25"|http://hostname.com:9704/analytics/saw.dll?Go&Path=/users/administrator/Test/TestReport&Action=Navigate&col1=TestReport.SUBJECT&op1=like&val1="%25D8D8%25"]
    Basically, we want to send the filter : SUBJECT like '%D8D8%' in the GoURL. However, the report that opens up does not fetch any rows because BI somehow messes up the clause by not recognizing the leading %25 (which is an escaped % character). Instead it resolves the %25D8D8%25 into something like �D8% .
    As you can see, the %25 at the end however gets resolved correctly but somehow the one at the beginning gets clubbed with the leading D8 to give �.
    Any idea, how to get BI to accept a leading escaped % character when doing a pattern match in the Go URL?

    I'm heading to the Apple Store in Danbury CT tomorrow to test out a MacBook Pro. I'll happily post what I like and dislike here.
    Waiting for a MacBook Pro...   Other OS  

  • Using LabVIEW to program a Pattern Trigger for the PCI-5112

    I am trying to program a pattern trigger for the PCI-5112.  Has anyone ever done this?  I am trying to use the the "Fetch forever" example as a base, then use the software trigger when there is a pattern match.
    Any help or advice with this would be very appreciated.
    PS as an example, I want to trigger when the pre-trigger data matches the pattern, say a 8 bit word such as 1010 0000.  Maybe I can try to do like my Tektonix TS5104B scope and try to program a timeout trigger.

    Good morning Andronicus,
    Thanks for contacting National Instruments with your issue, we'll try our best to resolve it for you as quickly and efficiently as possible.
    Unfortunately, there is no easy way to do what you're trying to accomplish with simply a Scope alone. The trigger input and PFI lines have no buffer and are only capable of looking for a single edge, and the standard CH0 and CH1 inputs strictly represent signals in analog. 
    So your current approach may be best, of using the Fetch Forever to acquire the signal into a prebuffer and then analyzing it and sending a software trigger.  So the best you can do in terms of response will be software-time, which is not ideal.  There is also the very tricky matter of interpreting that analog signal as a digital signal.  You'd have to know the clock rate of the incoming pattern and then also the phase in order to correctly assess the incoming pattern.  No easy task, and certainly nothing that would be super reliable or recommended.
    Your best bet would be to purchase one of our  HSDIO cards, such as the PCI-653x that inherently does pattern triggering in the hardware domain, and then route the start trigger (i.e. when the pattern has been matched) via a RTSI cable to the Scope card which can then simply use the digital edge trigger to begin it's acquisition.  This will be far more robust, easier to code and have a much quicker response time. 
    Best of luck with your project.
    Sincerely,
    Minh Tran
    Applications Engineering
    National Instruments

  • Is it possible to create an EQ setting (manual) in iTunes that can be stored on an iPod nano as an addition to the 22 EQ onpresets?  I want to use a manual setting for my headphones without applying the setting to each song.

    Hi.  Is it possible to create an EQ setting (manual) in iTunes that can be stored on an ipod nano as an addition to the 22 EQ presets?  I want to use a manual setting for my headphones without applying the EQ to all the individual songs.  I'd use a different EQ for my dock.
    Thanks.
    Paul St

    A quick look at the DM1 site shows that it works with Audiocopy.

  • I am trying to use the brightness adjustment on a grayscale photoshop CS6 file.  The preview shows the adjustment working and changes the brightness, but when you click to apply the change, it does not apply the adjustment.  I have run into this problem b

    I am trying to use the brightness adjustment on a grayscale photoshop CS6 file.  The preview shows the adjustment working and changes the brightness, but when you click to apply the change, it does not apply the adjustment.  I have run into this problem before, although rarely, with some other files over the years and with earlier versions of CS.  I would like to know how to overcome this problem?

    Make sure you are viewing your image at 100%. At smaller views, pixels and layers and the way they interact are approximate interpolations and won't show you the actual pixel-for-pixel changes.

  • Using trial of Photoshop CC but when trying 3D get "Could not apply the workspace because the disk is not available." can anyone help?

    I am trying out Photoshop CC  specifically the 3D facility but every time i go to 3D I get "Could not apply the workspace because the disk is not available"
    I have searched online for answer but cannot resolve this, can anyone advise?
    regards
    Drew.

    I am using a MacBook Air 
    Model Name: MacBook Air
      Model Identifier: MacBookAir6,2
      Processor Name: Intel Core i7
      Processor Speed: 1.7 GHz
      Number of Processors: 1
      Total Number of Cores: 2
      L2 Cache (per Core): 256 KB
      L3 Cache: 4 MB
      Memory: 8 GB

  • CS6 - Pattern making. How can I use a bounding box to define the pattern size?

    I want to create a pattern in cs6. As in the previous versions of illustrator, I'd like to be able to use a bounding box to tell the computer where I want the pattern to start etc. In cs6 I can't seem to be able to do this. Once I hit 'make pattern' the bounding box is different and it becomes really difficult to define where I want the pattern to start. The pattern making part of illustrator seems to get confused and ends up throwing out my pattern completely. Any ideas?
    Thanks!

    Zehgut,
    Create a nofill/nostroke rectangle where you want to have the boundaries, then move it down beneath the artwork in the Layers palette and include it in the swatch. That is the way to define the boudaries.

  • Hi there - I have a Mac and use the 15.0 version of Adobe Illustrator. I can't locate the pattern tool under the 'Options' tab. I also checked the help section and it doesn't exist.

    Hi there - I have a Mac and use the 15.0 version of Adobe Illustrator. I can't locate the pattern tool under the 'Options' tab. I also checked the help section and it doesn't exist.

    Thanks Manish!
    I was following the instructions my teacher sent and there was no mention of what program the tutorial used. I ended up finding a pattern tutorial for CS5.
    Rosa

  • I am using the pen tool to clipp an image. Sometimes when I apply the mask WITH NO FEATHER it still appears to be feathered? Does this have to do with Anti-aliasing

    I am using the pen tool to clipp an image. Sometimes when I apply the mask WITH NO FEATHER it still appears to be feathered? Does this have to do with Anti-aliasing?

  • Hello LR 5 is not showing me the Radial Gradients after I use them, it's been apply but I can't edit them since I can't click on them. (Linear gradients work fine)

    Hello LR 5 is not showing me the Radial Gradients after I use them, it's been apply but I can't edit them since I can't click on them. (Linear gradients work fine)

    [ H ] key to Hide/Unhide

  • Is normal that appear a spot  when i use the camera? and when you apply the zoom, the spot increases its size?

    Is normal that appear a spot  when i use the camera? and when you apply the zoom, the spot increases its size?

    Morning alex navarro,
    Thanks for using Apple Support Communities.
    For troubleshooting on this, take a look at this article:
    iPhone: Hardware troubleshooting
    http://support.apple.com/kb/TS2802
    Ensure the camera lens is clean and free from any obstructions. Use a microfiber polishing cloth to clean the lens.
    Third-party cases can interfere with the autofocus/exposure feature and the flash (iPhone 4 only); try removing the case if you have image-quality issues with photos.
    If your iPhone has a front and rear camera, try switching between them to verify if the issue persists on both.
    Hope this helps,
    Mario

  • Do not apply the latest upgrade to LR 4.2 if you are using PS5

    Do not apply the latest upgrade to LR 4.2 if you are using PS5. The latest LR update used Raw 7.2 which is not available in CS5.
    Wish I had a was to go backward. LR 4.2 was working fine until the latest upgrade.
    Wish I had not done it. NOW I am back to all the problems I had when I first installed LR4.0.
    Plus I am swamped with work through the Dec. So no time to spend days on the phone with support.
    Afraid to upgrade to PS6 as I cannot  aford any additional issues. Have lost my faith in adobe.

    There is nothing wrong with LR, it always works one way with whatever is the contemporary Photoshop version., and another way with all other software. CS5 is not the contemporary version with these newer Lightroom versions, CS6 is.
    If you have the latest PS as well as the latest LR, then the "Edit in Photoshop" command gets ACR to process the file, using LR settings.
    If you have different software or older software, either that cannot happen, or else is not certain to happen 100% compatibly. So a different method is used, as JimHess says: getting LR to render the file properly, instead of getting ACR to have a go (and perhaps get some things wrong).
    If you get a dialog box warning about ACR compatibility, you need to select "Render using Lightroom" rather than "Open anyway".
    If you no longer get this dialog (you have checked "don't show again") you can make it show again using the LR PReferences / general tab / "Reset all warning dialogs" button. That lets you select the proper option.
    The only caveat here, is that with this "render using LR"  method, the converted file has already  been named and saved to disk before you see it in PS. This means that when you finish your edit, you must Save the results to the filename already assigned, not to another name. Then LR will be looking in the right place, to see your PS edits. This also means that even if you don't save changes at all from PS, LR will still show a new image version anyway (unlike with the other method via ACR).

Maybe you are looking for