inheritance

Unit testing Grails domains that (over?) extend a base class that uses services

坚强是说给别人听的谎言 提交于 2019-12-24 03:41:48
问题 So, I have a base class that I want to extend most (but not all) of my domain classes from. The goal is that I can add the six audit information columns I need to any domain class with a simple extends . For both creation and updates, I want to log the date, user, and program (based on request URI). It's using a Grails service (called CasService) to find the currently logged on user. The CasService then uses Spring Security and a database call to get the relevant user information for that

Unit testing Grails domains that (over?) extend a base class that uses services

ε祈祈猫儿з 提交于 2019-12-24 03:41:20
问题 So, I have a base class that I want to extend most (but not all) of my domain classes from. The goal is that I can add the six audit information columns I need to any domain class with a simple extends . For both creation and updates, I want to log the date, user, and program (based on request URI). It's using a Grails service (called CasService) to find the currently logged on user. The CasService then uses Spring Security and a database call to get the relevant user information for that

Regarding Java subclasses inheriting methods that return “this”

僤鯓⒐⒋嵵緔 提交于 2019-12-24 03:37:10
问题 Have a class Car with a public method public Car myself() { return this; } Have a subclass Ferrari , and a variable foo that contains a Ferrari object. Finally, Ferrari bar = foo.myself(); This will warn you, because the method myself() returns a Car object, rather than the expected Ferrari . Note: I know that the example is stupid because you'd just do bar = foo . It's just an example. Solutions: Override the myself() method in Ferrari . Cast the Car object to a Ferrari object when assigning

A need for dynamic cast of a derived class: looking for an alternative approach

北战南征 提交于 2019-12-24 03:32:43
问题 I present my question in this simple form: class animal { public: animal() { _name="animal"; } virtual void makenoise(){ cout<<_name<<endl; } string get_name(){ return _name; } protected: string _name; }; class cat : public animal { public: cat() { this->_name="cat"; } }; class dog : public animal { public: dog() { this->_name = "dog"; } }; I want to store all animal types together in a single container such as: vector<animal*> container; barnyard.push_back(new animal()); barnyard.push_back

Calling member-function of generic member

独自空忆成欢 提交于 2019-12-24 03:29:47
问题 I've got a super-class (GraphNode) and sub-class (AStarNode). Both can be a member by another class thats why I turned the class which uses it into a generic class (GraphEdge). Inside this class I'd like to call some member-functions of the super-class but the compiler complains that: The method addEdge(GraphEdge<T>) is undefined for the type T How can I fix this or is my approach even ok? Here's some code that better describes the scenario: public class GraphNode { protected Graph graph;

Overriding a method that's in the superclass

僤鯓⒐⒋嵵緔 提交于 2019-12-24 02:58:15
问题 I have a method set in my superclass... public void explain() { for (Item item: Instances) { System.out.println(item.getname + " is in location " + item.place): } } I need to override this same method in the subclass to print out the original output message but the new instance for this method needs to print out different values that have been set in the subclass I'm confused with the overriding bit (as I know little about it) and would like an explanation. 回答1: So just give the method in

Accessing derived class' member functions in base template function

﹥>﹥吖頭↗ 提交于 2019-12-24 02:48:20
问题 I have a class called DBDriver that handles communication with a given table in a database. Its public entry point is a function template called execute_query() , which executes SELECT queries. Upon calling this function, some database logic is performed, and then a provided container (of the template type) is populated with results. This looks something like the following: class DBDriver { ... template <typename CONT_T> void execute_query(const std::string& query, CONT_T& container); ... };

Why Can't I Inherit IO.Directory?

时光总嘲笑我的痴心妄想 提交于 2019-12-24 02:41:06
问题 Why can't I create a class in VB.NET that inherits System.IO.Directory ? According to Lutz Roeder, it is not declared as NotInheritable ! I want to create a utility class that adds functionality to the Directory class . For instance, I want to add a Directory.Move function. Please advise and I will send you a six pack. OK nevermind I'm not sending you anything but if you come to the bar tonight I will hook you up and then beat you in pool. 回答1: From the Meta Data of .NET namespace System.IO {

Ignore base class / interfaces completely in entity framework 5 code first

本秂侑毒 提交于 2019-12-24 02:23:22
问题 I have the following entity class: [System.ComponentModel.DataAnnotations.Schema.Table("User")] public class User: UserBase, IPersistCustom<Entity> { ... } Depending on the type of hierarchy mapping you use, EF will generate either a descriptor column or split tables. Is there a way to have EF completely ignore the fact that this class inherits from something or implements an interface? I don't mean just ignoring base class properties. 回答1: If you mark your base class(es) as abstract and use

Ignore base class / interfaces completely in entity framework 5 code first

…衆ロ難τιáo~ 提交于 2019-12-24 02:23:11
问题 I have the following entity class: [System.ComponentModel.DataAnnotations.Schema.Table("User")] public class User: UserBase, IPersistCustom<Entity> { ... } Depending on the type of hierarchy mapping you use, EF will generate either a descriptor column or split tables. Is there a way to have EF completely ignore the fact that this class inherits from something or implements an interface? I don't mean just ignoring base class properties. 回答1: If you mark your base class(es) as abstract and use