visitor

Java field type for a value of a generically recursive self-type?

心不动则不痛 提交于 2020-01-11 05:58:15
问题 Given a class hierarchy where the base class defines a recursive self-type: abstract class A<T extends A<T>> { } How can I declare another class (which should not be generic in T, because such a T could vary over the lifetime of the object) with a field that can hold any subclass of A? The following does not work: public class B { //fails to compile, because the capture of ? is not sufficiently narrow private A<?> a; public <T extends A<T>> setA(T a) { this.a = a; } } -- END OF QUESTION -- I

Java field type for a value of a generically recursive self-type?

纵然是瞬间 提交于 2020-01-11 05:58:07
问题 Given a class hierarchy where the base class defines a recursive self-type: abstract class A<T extends A<T>> { } How can I declare another class (which should not be generic in T, because such a T could vary over the lifetime of the object) with a field that can hold any subclass of A? The following does not work: public class B { //fails to compile, because the capture of ? is not sufficiently narrow private A<?> a; public <T extends A<T>> setA(T a) { this.a = a; } } -- END OF QUESTION -- I

Optimizing a comparison over array elements with two conditions; C++ abstraction mechanisms?

孤街醉人 提交于 2020-01-01 19:28:12
问题 My question is a follow-up to How to make this code faster (learning best practices)?, which has been put on hold (bummer). The problem is to optimize a loop over an array with floats which are tested for whether they lie within a given interval. Indices of matching elements in the array are to be stored in a provided result array. The test includes two conditions (smaller than the upper threshold and bigger than the lower one). The obvious code for the test is if( elem <= upper && elem >=

Visitor and templated virtual methods

拜拜、爱过 提交于 2020-01-01 08:37:52
问题 In a typical implementation of the Visitor pattern, the class must account for all variations (descendants) of the base class. There are many instances where the same method content in the visitor is applied to the different methods. A templated virtual method would be ideal in this case, but for now, this is not allowed. So, can templated methods be used to resolve virtual methods of the parent class? Given (the foundation): struct Visitor_Base; // Forward declaration. struct Base { virtual

Translator Pattern

↘锁芯ラ 提交于 2020-01-01 05:37:06
问题 In a previous job, my manager suggested use of a Translator pattern for converting data from a DataTable to objects. Basically, the Translator class had only static (i.e. class) methods so it was an aggregation of function calls. My initial approach was to implement constructors for each object that could take a DataTable row as an argument and create an instance that corresponded to the data. He said that the Translator class had been suggested by Microsoft, and provided better modularity of

Use/Need of Visitor Pattern in prog. lang. that support class extensions or open classes

血红的双手。 提交于 2019-12-25 02:02:49
问题 I'm confronted with the following software design question: Is there still a need for the Visistor pattern in a programming language that supports open classes or class extensions? I'm unsure. It can still be implemented, obviously, but it could also be replaced. 回答1: Your question is not entirely valid. Should OOP-principle X be replaced by language feature Y? actually can never be answered because OOP principles are logically preceding language design questions, which are to a certain

Magento. Save visitor store choice in cookies

我的梦境 提交于 2019-12-24 11:10:12
问题 I need to check if visitor is first time on website and show block with country choice(stores). Then I need to save visitor choice in cookies(I just think that it is right to save it in cookies). Maybe someone did that and\or can help? Thanks. 回答1: When the user lands on the page check if a cookie is set, if it is then redirect to the store view based on the cookie value. I'm pretty new to magento so there is probably a better way to do this, but i needed something similar myself. I had a

Observer pattern + Visitor pattern for message system

ぃ、小莉子 提交于 2019-12-22 12:17:13
问题 Recently I got into implementing a message dispatching system that uses the "Observer pattern": nothing special here. As I developed it I thought it would be nice to send "Message" objects from the "subject" that could be fundamentally different from each other and could be read from the many "observers". These different messages took the form of different message classes (for example, think about the "User Logout message", "Screen mode toogle" and "Volume level changed", all of these need

Iterating hierarchy of nodes - Visitor and Composite?

我只是一个虾纸丫 提交于 2019-12-21 09:34:34
问题 Let's imagine I have a collection of nodes that I use for my Renderer class later on. Then I have a Visitor class that can visit node or whole collection. It's simple because my collection of nodes it's simply a wrapper to the std::list with few extra methods. The problem is I'd like to have a tree like structure for nodes(instead of simple list) so a node can have a parent and n children. That would be handy as I'd like to be able to pass to my Renderer a node and render everything "below"

Boost Graph Library and Visitors

时间秒杀一切 提交于 2019-12-21 05:16:22
问题 I'm writing a library for manipulating bond graphs, and I'm using the Boost Graph Library to store the data for me. Unfortunately, I can't seem to figure out how to implement a proper visitor pattern using it, as you can't subclass out vertices - you must rely on 'properties' instead. The visitor framework provided in the library seems heavily geared towards working with certain algorithms where vertices are all of the same type, but store different information. In my problem, the vertices