Search Results

Search found 42264 results on 1691 pages for 'template method pattern'.

Page 13/1691 | < Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >

  • Template function in C# - Return Type?

    - by LifeH2O
    It seems that c# does not support c++ like templates. template <class myType> myType GetMax (myType a, myType b) { return (a>b?a:b); } I want my function to have return type based on its parameters, how can i achieve this in c#? How to use templates in C#

    Read the article

  • django url from another template than the one associated with the view-function

    - by dana
    Heyy there, i have an application, and in my urls.py i have something like that: urlpatterns = patterns('', url(r'^profile_view/(?P<id>\d+)/$', profile_view, name='profile_view'),) meaning that the profile_view function has id as a parameter. Now, i want to call that function from another template than the one associated with the def-view that has this url. How should i do that? i have to put two render_to_response to one same function, in order to render the objects from both models? thank you!

    Read the article

  • Template class + virtual function = must implement?

    - by sold
    This code: template <typename T> struct A { T t; void DoSomething() { t.SomeFunction(); } }; struct B { }; A<B> a; is easily compiled without any complaints, as long as I never call a.DoSomething(). However, if I define DoSomething as a virtual function, I will get a compile error saying that B doesn't declare SomeFunction. I can somewhat see why it happens (DoSomething should now have an entry in the vtable), but I can't help feeling that it's not really obligated. Plus it sucks. Is there any way to overcome this? EDIT 2: Okay. I hope this time it makes sence: Let's say I am doing intrusive ref count, so all entities must inherit from base class Object. How can I suuport primitive types too? I can define: template <typename T> class Primitive : public Object { T value; public: Primitive(const T &value=T()); operator T() const; Primitive<T> &operator =(const T &value); Primitive<T> &operator +=(const T &value); Primitive<T> &operator %=(const T &value); // And so on... }; so I can use Primitive<int>, Primitive<char>... But how about Primitive<float>? It seems like a problem, because floats don't have a %= operator. But actually, it isn't, since I'll never call operator %= on Primitive<float>. That's one of the deliberate features of templates. If, for some reason, I would define operator %= as virtual. Or, if i'll pre-export Primitive<float> from a dll to avoid link errors, the compiler will complain even if I never call operator %= on a Primitive<float>. If it would just have fill in a dummy value for operator %= in Primitive<float>'s vtable (that raises an exception?), everything would have been fine.

    Read the article

  • c++ template function compiles in header but not implementation

    - by flies
    I'm trying to learn templates and I've run into this confounding error. I'm declaring some functions in a header file and I want to make a separate implementation file where the functions will be defined. Here's the code that calls the header (dum.cpp): #include <iostream> #include <vector> #include <string> #include "dumper2.h" int main() { std::vector<int> v; for (int i=0; i<10; i++) { v.push_back(i); } test(); std::string s = ", "; dumpVector(v,s); } now, here's a working header file (dumper2.h): #include <iostream> #include <string> #include <vector> void test(); template <class T> void dumpVector( std::vector<T> v,std::string sep); template <class T> void dumpVector(std::vector<T> v, std::string sep) { typename std::vector<T>::iterator vi; vi = v.begin(); std::cout << *vi; vi++; for (;vi<v.end();vi++) { std::cout << sep << *vi ; } std::cout << "\n"; return; } with implentation (dumper2.cpp): #include <iostream> #include "dumper2.h" void test() { std::cout << "!olleh dlrow\n"; } the weird thing is that if I move the code that defines dumpVector from the .h to the .cpp file, I get the following error: g++ -c dumper2.cpp -Wall -Wno-deprecated g++ dum.cpp -o dum dumper2.o -Wall -Wno-deprecated /tmp/ccKD2e3G.o: In function `main': dum.cpp:(.text+0xce): undefined reference to `void dumpVector<int>(std::vector<int, std::allocator<int> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' collect2: ld returned 1 exit status make: *** [dum] Error 1 So why does it work one way and not the other? Clearly the compiler can find test(), so why can't it find dumpVector?

    Read the article

  • C++: combine const with template arguments

    - by awn
    The following example is working when I manualy replace T wirh char *, but why is not working as it is: template <typename T> class A{ public: A(const T _t) { } }; int main(){ const char * c = "asdf"; A<char *> a(c); } When compiling with gcc, I get this error: test.cpp: In function 'int main()': test.cpp:10: error: invalid conversion from 'const char*' to 'char*' test.cpp:10: error: initializing argument 1 of 'A<T>::A(T) [with T = char*]'

    Read the article

  • Exception handling pattern

    - by treefrog
    It is a common pattern I see where the error codes associated with an exception are stored as Static final ints. when the exception is created to be thrown, it is constructed with one of these codes along with an error message. This results in the method that is going to catch it having to look at the code and then decide on a course of action. The alternative seems to be- declare a class for EVERY exception error case Is there a middle ground ? what is the recommended method ?

    Read the article

  • Template function in define

    - by Ockonal
    Hello, I have some template function and I want to call it using define in c++: #define CONFIG(key, type, def) getValue<type>(key, def); Of course, it won't work. Could I make something like this?

    Read the article

  • Are Promises/A a good event design pattern to implement even in synchronous languages like PHP?

    - by Xeoncross
    I have always kept an eye out for event systems when writing code in scripting languages. Web applications have a history of allowing the user to add plugins and modules whenever needed. In most PHP systems you have a global/singleton event object which all interested parties tie into and wait to be alerted to changes. Event::on('event_name', $callback); Recently more patterns like the observer have been used for things like jQuery. $(el).on('event', callback); Even PHP now has built in classes for it. class Blog extends SplSubject { public function save() { $this->notify(); } } Anyway, the Promises/A proposal has caught my eye. It is designed for asynchronous systems, but I'm wondering if it is also a good design to implement now that even synchronous languages like PHP are changing. Combining Dependency Injection with Promises/A seems it might be the best combination for handling events currently.

    Read the article

  • MVC repository pattern design decision

    - by bradjive
    I have an asp .net MVC application and recently started implementing the repository pattern with a service validation layer, much like this. I've been creating one repository/service for each model that I create. Is this overkill? Instead, should I create one repository/service for each logical business area that provides CRUD for many different models? To me, it seems like I'm either cluttering the project tree with many files or cluttering a class with many methods. 6 one way half dozen the other. Can you think of any good arguments either way?

    Read the article

  • Using a Generic Repository pattern with fluent nHibernate

    - by alex
    I'm currently developing a medium sized application, which will access 2 or more SQL databases, on different sites etc... I am considering using something similar to this: http://mikehadlow.blogspot.com/2008/03/using-irepository-pattern-with-linq-to.html However, I want to use fluent nHibernate, in place of Linq-to-SQL (and of course nHibernate.Linq) Is this viable? How would I go about configuring this? Where would my mapping definitions go etc...? This application will eventually have many facets - from a WebUI, WCF Library and Windows applications / services. Also, for example on a "product" table, would I create a "ProductManager" class, that has methods like: GetProduct, GetAllProducts etc... Any pointers are greatly received.

    Read the article

  • Parametrized Strategy Pattern

    - by ott
    I have several Java classes which implement the strategy pattern. Each class has variable number parameters of different types: interface Strategy { public data execute(data); } class StrategyA implements Strategy { public data execute(data); } class StrategyB implements Strategy { public StrategyB(int paramA, int paramB); public data execute(data); } class StrategyB implements Strategy { public StrategyB(int paramA, String paramB, double paramC); public data execute(data); } Now I want that the user can enter the parameters in some kind of UI. The UI should be chosen at runtime, i.e. the strategies should be independent of it. The parameter dialog should not be monolithic and there should be the possibility to make it behave and look different for each strategy and UI (e.g. console or Swing). How would you solve this problem?

    Read the article

  • myth about factory pattern

    - by leiz
    This has bothered me for awhile, and I have no clues if this is a myth. It seems that a factory pattern can ease the pain of adding a dependency for a class. For example, in a book, it has something like this Suppose that you have a class named Order. Initially it did not depend on anything. Therefore you didn't bother using a factory to create Order objects and you just used plain new to instantiate the objects. However, you now have a requirement that Order has to be created in association with a Customer. There are million places you need to change to add this extra parameter. If only you had de?ned a factory for the Order class, you would have met the new requirement without the same pain. How is this not same pain as adding an extra parameter to the constructor? I mean you would still need to provide an extra argument for the factory and that is also used by million places, right?

    Read the article

  • C# ProgressBar design pattern

    - by MadSeb
    Hi, I'm working on a database upgrader application. The upgrader updates the schema of a database ( adds new columns, renames columns , adds new tables, new views to an existing database by executing SQL statements ). When a user wants to upgrade from version 1.0 to 2.0 , "Upgrader" objects are taken from an object factory and the "Execute" method of each "Upgrader" is called. The GUI of the application has a progress bar and each time an upgrader object performs a SQL statement the progress bar gets incremented. while (!version.Equal(CurrentVersion)) { IUpgrader myUpgrader = UpgraderFactory.GetUpgrader(version); myUpgrader.Execute(UpgradedFile,progressbar); version.Increment(); } My question is very simple : how should the upgrader object communicate with the progressbar. In the code above, the upgrader object is given direct access to the progressbar but I'm wondering if some better way of doing this or better design pattern exists. Regards, Seb

    Read the article

  • makefile pattern rules: single wildcard, multiple instances in prerequisite

    - by johndashen
    Hi all, hopefully this is a basic question about make pattern rules: I want to use a wildcard more than once in a prerequisite for a rule, i.e. in my Makefile I have data/%P1.m: $(PROJHOME)/data/%/ISCAN/%P1.RAW @echo " Writing temporary matlab file for $*" # do something data/%P2.m: $(PROJHOME)/data/%/ISCAN/AGP2.RAW @echo " Writing temporary matlab file for $*" # do something In this example, I try to invoke make when the wildcard % is AG. Both files $(PROJHOME)/data/AG/ISCAN/AGP1.RAW and $(PROJHOME)/data/AG/ISCAN/AGP2.RAW exist. I attempt the following make commands and get this output: [jshen@iLab10 gender-diffs]$ make data/AGP1.m make: *** No rule to make target `data/AGP1.m'. Stop. [jshen@iLab10 gender-diffs]$ make data/AGP2.m Writing temporary matlab file for AG, part 2... [jshen@iLab10 gender-diffs]$ ls data/AG/ISCAN/AG* data/AG/ISCAN/AGP1.RAW data/AG/ISCAN/AGP2.RAW How can I implement multiple instances of the same wildcard in the first make rule?

    Read the article

  • augment the factory pattern in java

    - by TP
    I am trying to use a factory pattern to create a QuestionTypeFactory where the instantiated classes will be like MultipleChoice, TrueFalseQuestion etc. The factory code looks something like this class QuestionFactory { public enum QuestionType { TrueFalse, MultipleChoice, Essay } public static Question createQuestion(QuestionType quesType) { switch (quesType) { case TrueFalse: return new TrueFalseQuestion(); case MultipleChoice: return new MultipleChoiceQuestion(); case Essay: return new EssayQuestion(); } throw new IllegalArgumentException("Not recognized."); } } This works ok for now. If I want to add another question type I will need to modify the factory class and I do not want to do that. How can I set it up so that each question class registers itself with the Factory so that when I add a new question type, I do not have to change the code for the factory? I am a bit new to java and am not sure how to do this.

    Read the article

  • State pattern: Why doesn't the context class implement or inherit the State abstract interface/class

    - by Ricket
    I'm reading about the State pattern. I have only just begun, so of course I begin by reading the entire Wikipedia article on it. I noticed that both of the examples in the article have some base abstract class or Java interface for a generic State's methods/functions. Then there are some states which inherit from the base and implement those methods/functions in different ways. Then there's a Context class which has a private member of type State and which, at any time, can be equal to an instance of one of the implementations. That context class also implements the same methods, and passes them onto the current state instance, and then has an additional method to change the state (or depending on design I understand the change of state could be a reaction to one of the implemented methods). Why doesn't this context class specifically "extend" or "implement" the generic State base class/interface?

    Read the article

  • C++ visitor pattern handling templated string types?

    - by Steve the Plant
    I'm trying to use the visitor pattern to serialize the contents of objects. However one snag I'm hitting is when I'm visiting strings. My strings are of a templated type, similar to STL's basic_string. So something like: basic_string<char_type, memory_allocator, other_possible_stuff> \\ many variations possible! Since I can have very many different templated string types, I can't go and add them to my visitor interface. It would be ridiculous. But I can't add templates to my VisitString method because C++ prevents using templates parameters in virtual methods. So what are my options to work around this?

    Read the article

  • LLBLGen and the repository pattern

    - by user137348
    I was wondering if building a repository on the top LLBLGen (adapter) is a good idea. I don't want to overengineer and reinvent the wheel again. The DataAccessAdapter class could be some kind of a generic repository.It has all the CRUD methods you need. But on the other side for a larger project it could be good to have a layer between your ORM and service layer. I'd like to hear your opinions, if your using the repository pattern with LLBLGen,if yes why if no why not. If you have some implementation, post it please.

    Read the article

< Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >