Where to put methods in a abstract base class - subclasses system
Hi,
I’d like to ask a question on some basic design practice.
When there are methods which are common in some subclasses so I would like to “move them up” in the base abstract class, I would also like to make sure that the ADT concept of the base class itself is not broken. So I don’t want to have methods in the base class that are not general enough to be there. How to resolve this?
For example I create a base abstract class Vehicle. Then I create subclasses Plane and Tanker and realize that the startEnginge() method in them is the same and in order remove the duplicated code, I can put it in Vehicle. But later there may be Bicycle or Sled subclasses which don’t need startEngine().
In a broader sense, I would like to keep the Vehicle class as similar to the real word concept of vehicles as possible. And not evey vehicle have engine of course.
What is the solution?
Extending the class hierarchy by injecting another abstract class between the base and the subclasses? (e.g: VehicleWithEngine)
I suppose I can’t use Interfaces because I need to have the common implemenations as well.
Thanks for any comments in advance,
lemonboston
ps: I am a beginner and don't know the terminology, so if there are programming expression for the followings for example, I would be thankful if someone could help with this too:
- moving common methods up in the class hierarchy
- injecting a class in the hierarchy
- abstract base class - subclasses system
lemonboston wrote:
Hi,
I’d like to ask a question on some basic design practice.
When there are methods which are common in some subclasses so I would like to “move them up” in the base abstract class, I would also like to make sure that the ADT concept of the base class itself is not broken. So I don’t want to have methods in the base class that are not general enough to be there. How to resolve this?
You are talking about code.
Instead you need to talk about the design.
The base class represents conceptually a 'type' of something. That 'type' defines behavior. That behavior is what goes in the base class nothing else (in terms of design.)
If you have common functionality which does not fit into the definition (design) of the 'type' then you put it in another class and use (composition) that class in the sub class.
For example I create a base abstract class Vehicle. Then I create subclasses Plane and Tanker and realize that the startEnginge() method in them is the same and in order remove the duplicated code, I can put it in Vehicle. But later there may be Bicycle or Sled subclasses which don’t need startEngine(). No that is not how it works.
You have specific examples of some vehicles and then you need to manage those types generically. That is the first step.
Second step is then to determine what the exact 'type' is that you want to manage. And you use the requirements of the need to create the 'type'.
Then you look at the specific examples to determine how they will meet the needs of the type.
Thus if I have an application that must start the engines of all the vehicles in the city then I must have a vehicle class which has startEngine.
But if I have an application that manages vehicles as inventory (like a retail store) and then decide that because my examples both have engines that I might as well move it into the base class. In that case there is no 'need' for the application to manage starting vehicles. The fact that both have engines is irrelevant.
So looking back at your example you have stated functionality about your specific types but you have not stated anything about why your application needs to deal with that functionality generically.
Another way to think about it is that you do not put the shared functionality in the base because you can but rather because you must.
Similar Messages
-
What is the correct way to model an abstract base class/table?
I tried to model an abstract base class/table. For the parent table I used the "Forward Engineer Strategy" "Table per child" and I set on each child table the "Super Type" to the corresponding parent table. I did this for two parent tables and five child tables. This is the result:
https://lh5.googleusercontent.com/-1La98ulWOZg/T_2Hyock5-I/AAAAAAAAAoI/00qn5ukJCpI/s678/2012-07-11
But when I engineer the logical model into a physical model, the result is not as expected:
https://lh5.googleusercontent.com/-YfF_ocUa8bY/T_2H_YSqkyI/AAAAAAAAAoc/rNEYRnTFzU4/s617/2012-07-11
First the parent table "obj" should not be created. The table is correctly omitted, but the primary key of the parent table gets created. For me this is not logical. And even worse the primary key gets created twice with the same name, which results in a DDL generation error.
And second the primary key of the "attr" table does not get merged into the primary key of the child tables. This results into two individual unique constraints although I have expected to create only one with two attributes.
Is this a bug or is there another way to model this example correctly?chriswalsh wrote:
The installer for Silverlight installed it as a seperate volume displayed on the desktop...
Likely that's not the app itself. When you download most Mac software, you are downloading a .dmg file (a disk image) - opening that (which may happen automatically) mounts a disk image on your desktop, and then you drag the app from that disk image to your Applications folder (or an installer runs).
After copying/installing the app, you Eject the disk image, then delete the .dmg file (from your Downloads folder, probably). -
Hi folks, this isn't a Java dependant question but since I am coding in Java I will ask it here. I have a value object that contains a few attributes, accessor and persistence methods. We'll call the Class Player and it contains details of a person who is playing a game. All of the methods and attributes belonging to this Class are related to an instance of Player. I want to have a utility method that returns ALL the players. What do people of the group think is the best way to treat this method? Should I add a new Class i.e. PlayerUtils, where I could subsequently add more utility methods OR would adding a method to the Player Class, public static Vector getAllPlayers() be a viable option? My gut feeling is to go with the PlayerUtils Class even though there is only one method so far because it is more flexbile and it keeps static method calls out of my instance Class. I don't really have any formal training in Java so most of what I have learned is through experience and reference-type books. Your thoughts are valued.
Thanks, MaxThis is like a singleton, except it is a "multipleton". (I haven't studied my design patterns well yet, maybe it has a name.) I agree that keeping the collection information in another class might be a better idea, but this Player class could also do its own enforcing that certain Player fields (such as name) acts like primary keys and are not duplicated.
class Player
// static field
private static Vector allPlayers = new Vector();
// private constr
private Player(<args>)
public static Player createNewPlayer(<args>)
Player newguy = new Player(args);
allPlayers.add(newguy);
return newguy;
public static Player getPlayerByName(String name)
... // assuming Player has a Name field, find him
public static Vector getAllPlayers()
return allPlayers; // or a copy of it -
Can I map descriptors to abstract base classes?
For example can I map to BaseAccount object which has an abstract method
calcPayment? thanksWhy is TopLink attempting to instantiate the Abstract Class. You should not have any data in the database that represents the AbstractClass and you would not be able to create one in attempt to persist it.
--Gordon -
Where to put removeChild (Away3d 4.x)
Hey guys i need some help on how to change primitives and removing the previous primitive showing in the scene and also changing materials on the primitive with a click of a button.
Mainly just where to put removeChild.
This is for Away3d
package
import away3d.cameras.*;
import away3d.containers.*;
import away3d.controllers.*;
import away3d.core.base.SubGeometry;
import away3d.core.base.data.Vertex;
import away3d.debug.*;
import away3d.entities.Mesh;
import away3d.extrusions.*;
import away3d.filters.*;
import away3d.lights.*;
import away3d.materials.*;
import away3d.materials.lightpickers.*;
import away3d.materials.methods.*;
import away3d.primitives.*;
import away3d.textures.*;
import away3dplus.controllers.SimpleHoverController;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Vector3D;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
[SWF(backgroundColor="#000000",frameRate="30",quality="LOW")]
public class Main extends Sprite
//engine variables
private var view:View3D;
private var scene:Scene3D;
// debug
private var awayStats:AwayStats;
//light objects
private var pointLight:PointLight;
private var lightPicker:StaticLightPicker;
//material objects
private var redColorMaterial:ColorMaterial;
private var skyBoxCubeTexture:BitmapCubeTexture;
//Buttons
private var btnCube:Sprite = new Sprite
private var btnSphere:Sprite = new Sprite
private var btnCylinder:Sprite = new Sprite
private var btnTorus:Sprite = new Sprite
private var btnMaterial:Sprite = new Sprite
private var btnWireframe:Sprite = new Sprite
public function Main() {
init();
private function init():void {
initEngine();
initLights();
initCamera();
initMaterials();
initObjects();
initListeners();
drawButton()
btnCube.addEventListener(MouseEvent.CLICK, changeCube);
btnCube.x = 400;
btnCube.y = 25;
addChild(btnCube);
btnSphere.addEventListener(MouseEvent.CLICK, changeSphere);
btnSphere.x = 400;
btnSphere.y = 60;
addChild(btnSphere);
btnCylinder.addEventListener(MouseEvent.CLICK, changeCylinder);
btnCylinder.x = 400;
btnCylinder.y = 95;
addChild(btnCylinder);
btnTorus.addEventListener(MouseEvent.CLICK, changeTorus);
btnTorus.x = 400;
btnTorus.y = 130;
addChild(btnTorus);
//btnMaterial.addEventListener(MouseEvent.CLICK, changeMaterial);
btnMaterial.x = 15;
btnMaterial.y = 95;
addChild(btnMaterial);
btnWireframe.addEventListener(MouseEvent.CLICK, changeWireframe);
btnWireframe.x = 15;
btnWireframe.y = 130;
addChild(btnWireframe);
* Initialise the engine
private function initEngine():void {
//stage setup
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
// 3d view - window into 3d scene
view = new View3D();
addChild(view);
// 3d scene.
scene = view.scene;
// stats
awayStats = new AwayStats(view);
addChild(awayStats);
* Initialise the lights
private function initLights():void {
//point light
pointLight = new PointLight();
scene.addChild(pointLight);
lightPicker = new StaticLightPicker([pointLight]);
private function initCamera():void {
var hoverCameraManager:SimpleHoverController = new SimpleHoverController(view, 700, [pointLight]);
* Initialise Buttons
private function drawButton():void {
var textLabel:TextField = new TextField()
btnCube.graphics.clear();
btnCube.graphics.beginFill(0xFFFFFF); // white
btnCube.graphics.drawRoundRect(0, 0, 80, 25, 10, 10); // x, y, width, height, ellipseW, ellipseH
textLabel.text = "CUBE";
textLabel.x = 22;
textLabel.y = 4;
textLabel.selectable = false;
btnCube.addChild(textLabel)
var textLabel01:TextField = new TextField()
btnSphere.graphics.clear();
btnSphere.graphics.beginFill(0xFFFFFF); // white
btnSphere.graphics.drawRoundRect(0, 0, 80, 25, 10, 10); // x, y, width, height, ellipseW, ellipseH
textLabel01.text = "SPHERE";
textLabel01.x = 18;
textLabel01.y = 3;
textLabel01.selectable = false;
btnSphere.addChild(textLabel01)
var textLabel03:TextField = new TextField()
btnCylinder.graphics.clear();
btnCylinder.graphics.beginFill(0xFFFFFF); // white
btnCylinder.graphics.drawRoundRect(0, 0, 80, 25, 10, 10); // x, y, width, height, ellipseW, ellipseH
textLabel03.text = "CYLINDER";
textLabel03.x = 10;
textLabel03.y = 3;
textLabel03.selectable = false;
btnCylinder.addChild(textLabel03)
var textLabel04:TextField = new TextField()
btnTorus.graphics.clear();
btnTorus.graphics.beginFill(0xFFFFFF); // white
btnTorus.graphics.drawRoundRect(0, 0, 80, 25, 10, 10); // x, y, width, height, ellipseW, ellipseH
textLabel04.text = "TORUS";
textLabel04.x = 17;
textLabel04.y = 3;
textLabel04.selectable = false;
btnTorus.addChild(textLabel04)
var textLabel05:TextField = new TextField()
btnMaterial.graphics.clear();
btnMaterial.graphics.beginFill(0xFFFFFF); // white
btnMaterial.graphics.drawRoundRect(0, 0, 80, 25, 10, 10); // x, y, width, height, ellipseW, ellipseH
textLabel05.text = "MATERIAL";
textLabel05.x = 6;
textLabel05.y = 3;
textLabel05.selectable = false;
btnMaterial.addChild(textLabel05)
var textLabel06:TextField = new TextField()
btnWireframe.graphics.clear();
btnWireframe.graphics.beginFill(0xFFFFFF); // white
btnWireframe.graphics.drawRoundRect(0, 0, 80, 25, 10, 10); // x, y, width, height, ellipseW, ellipseH
textLabel06.text = "WIREFRAME";
textLabel06.x = 2;
textLabel06.y = 3;
textLabel06.selectable = false;
btnWireframe.addChild(textLabel06)
* Initialise the materials
private function initMaterials():void {
// red color
redColorMaterial = new ColorMaterial(0xFF0000, 0.8);
redColorMaterial.lightPicker = lightPicker;
skyBoxCubeTexture = new BitmapCubeTexture(new EnvPosX().bitmapData, new EnvNegX().bitmapData, new EnvPosY().bitmapData, new EnvNegY().bitmapData, new EnvPosZ().bitmapData, new EnvNegZ().bitmapData);
* Initialise the scene objects
private function initObjects():void {
var trident:Trident = new Trident(100);
trident.x = 0;
trident.y = 0;
scene.addChild(trident);
//Geometry - Geometry is a collection of SubGeometries, each of which contain the actual geometrical data such as vertices, normals, uvs, etc.
////PrimitiveBase - PrimitiveBase is an abstract base class for mesh primitives, which are prebuilt simple meshes.
//CubeGeometry A Cube primitive mesh.
var newCubeGeometry:CubeGeometry = new CubeGeometry(200, 200, 200, 50, 50, 50, true);
//SphereGeometry - A UV Sphere primitive mesh.
var newSphereGeometry:SphereGeometry = new SphereGeometry(50, 16, 12, true);
//CapsuleGeometry A UV Capsule primitive mesh.
var newCapsuleGeometry:CapsuleGeometry = new CapsuleGeometry(50, 100, 16, 12, true);
//ConeGeometry A UV Cone primitive mesh.
//var newConeGeometry:ConeGeometry = new ConeGeometry(50, 100, 16, 1, true, true);
//CylinderGeometry A UV Cylinder primitive mesh.
var newCylinderGeometry:CylinderGeometry = new CylinderGeometry(50, 50, 100, 16, 1, true, true);
//PlaneGeometry A Plane primitive mesh.
var newPlaneGeometry:PlaneGeometry = new PlaneGeometry(100, 100, 1, 1, true);
//RegularPolygonGeometry A UV RegularPolygon primitive mesh.
var newRegularPoligonGeometry:RegularPolygonGeometry = new RegularPolygonGeometry(100, 16, true);
//TorusGeometry A UV Torus primitive mesh.
var newTorusGeomentry:TorusGeometry = new TorusGeometry(50, 50, 15, 8, true);
// Entity - The Entity class provides an abstract base class for all scene graph objects that are considered having a "presence" in the scene,
// in the sense that it can be considered an actual object with a position and a size (even if infinite or idealised), rather than a grouping.
//Mesh - Mesh agregates instance of a Geometry, augmenting it with a presence in the scene graph, a material, and an animations tate.
// It consists out of SubMeshes, which in turn correspond to SubGeometries. SubMeshes allow different parts of the geometry to be assigned different materials.
//var cube:Mesh = new Mesh(newCubeGeometry, redColorMaterial);
//cube.x = 100;
//cube.y = 100;
//cube.z = 100;
//scene.addChild(cube);
//var sphere:Mesh = new Mesh(newSphereGeometry, redColorMaterial);
//sphere.x = -75;
//sphere.y = -150;
//scene.addChild(sphere);
//var capsule:Mesh = new Mesh(newCapsuleGeometry, redColorMaterial);
//capsule.x = -200;
//capsule.y = -150
//scene.addChild(capsule);
//var cone:Mesh = new Mesh(newConeGeometry, redColorMaterial);
//cone.x = -200;
//cone.y = 150;
//cone.showBounds = true;
//scene.addChild(cone);
//var cylinder:Mesh = new Mesh(newCylinderGeometry, redColorMaterial);
//cylinder.x = -75;
//cylinder.y = 150;
//scene.addChild(cylinder);
//var plane:Mesh = new Mesh(newPlaneGeometry, redColorMaterial);
//plane.x = -75;
//plane.y = 275;
//scene.addChild(plane);
//var poligon:Mesh = new Mesh(newRegularPoligonGeometry, redColorMaterial);
//poligon.x = -275;
//poligon.y = 275;
//scene.addChild(poligon);
//var torus:Mesh = new Mesh(newTorusGeomentry, redColorMaterial);
//torus.x = -275;
//scene.addChild(torus);
//SkyBox A SkyBox class is used to render a sky in the scene.
//var skyBox:SkyBox = new SkyBox(skyBoxCubeTexture);
//scene.addChild(skyBox);
// SegmentSet
//WireframeAxesGrid - Class WireframeAxesGrid generates a grid of lines on a given planeWireframeAxesGrid
//var wireFrameAxesGrid:WireframeAxesGrid = new WireframeAxesGrid(4, 400, 1);
//scene.addChild(wireFrameAxesGrid);
//WireframeGrid Class WireframeGrid generates a grid of lines on a given planeWireframeGrid
//var wireframeGrid:WireframeGrid = new WireframeGrid(10, 100, 5, 0x0000FF);
//wireframeGrid.x = 75;
//wireframeGrid.y = 275;
//scene.addChild(wireframeGrid);
//WireframePrimitiveBase
//WireframeCube - Class WireFrameGrid generates a grid of lines on a given planeWireFrameGrid
//var wireFrameCube:WireframeCube = new WireframeCube(100, 100, 100, 0x0000FF, 5);
//wireFrameCube.x = 75;
//scene.addChild(wireFrameCube);
//WireframeSphere - Class WireFrameGrid generates a grid of lines on a given planeWireFrameGrid
//var wireFrameSphere:WireframeSphere = new WireframeSphere(50, 16, 12, 0x0000FF, 5);
//wireFrameSphere.x = 75;
//wireFrameSphere.y = -150;
//scene.addChild(wireFrameSphere);
//WireframePlane
//var wireframePlane:WireframePlane = new WireframePlane(100, 100, 10, 10, 0x0000FF, 5);
//wireframePlane.x = 175;
//wireframePlane.y = 275;
//scene.addChild(wireframePlane);
* Initialise the listeners
private function initListeners():void {
addEventListener(Event.ENTER_FRAME, onEnterFrame);
* render loop
private function onEnterFrame(event:Event):void {
view.render();
* Intialise the buttons events
private function changeCube(event:MouseEvent):void {
var newCubeGeometry:CubeGeometry = new CubeGeometry(200, 200, 200, 50, 50, 50, true);
var cube:Mesh = new Mesh(newCubeGeometry, redColorMaterial);
cube.x = 100;
cube.y = 100;
cube.z = 100;
scene.addChild(cube);
private function changeSphere(event:MouseEvent):void {
var newSphereGeometry:SphereGeometry = new SphereGeometry(50, 16, 12, true);
var sphere:Mesh = new Mesh(newSphereGeometry, redColorMaterial);
scene.addChild(sphere);
private function changeCylinder(event:MouseEvent):void {
var newCylinderGeometry:CylinderGeometry = new CylinderGeometry(50, 50, 100, 16, 1, true, true);
var cylinder:Mesh = new Mesh(newCylinderGeometry, redColorMaterial);
scene.addChild(cylinder);
private function changeTorus(event:MouseEvent):void {
var newTorusGeomentry:TorusGeometry = new TorusGeometry(50, 50, 15, 8, true);
var torus:Mesh = new Mesh(newTorusGeomentry, redColorMaterial);
scene.addChild(torus);
private function changeWireframe(event:MouseEvent):void {
var wireFrameCube:WireframeCube = new WireframeCube(100, 100, 100, 0x0000FF, 5);
scene.addChild(wireFrameCube);
Thanks, MatthewFraudulent seller.
I received an empty package.- -
Back to the drawing board.
Thanks for your replies.
eBay is going through their required steps.
It will take a week or better to get my refund.
Thanks
Shopping for another "Mac Pro Late 2013" or I might settle for my "Mac Mini 2012 i7 16 Gig 256 SSD Intel 4000" refurb with warranty bought from Apple that I already have on hand.
Thank You
I don't know how this ended upon two threads.
I'm pretty sure I'm going to go with my 2012 Mac Mini i7 16 gig 256 SSD and Lacie Little Big Thunderbolt 1 512 SSD
That will be pretty punchy for me.
I'll only have about $1,000 in the computer itself with a three year Apple Care Warranty.
It should sell for $500 a year from now if I choose too.
I think it's going to work great.
I'm going to load it up with all of the software just like I was going to do on the Mac Pro.
It's good for three computers in the future so no money lost on the software
I'll probably just keep the Mini indefinitely for a backup even after I upgrade to the newer 2015 Mac Pro later next year.
Thanks -
Abstract Graphics class ???ques???
Referring to the abstract methods within this class such as drawPolyline and drawPolygon, etc . . . it says in the documentation for Class Graphics:
"The Graphics class is the abstract base class for all graphics contexts that allow an application to draw onto components that are realized on various devices, as well as onto off-screen images."
There are no sub-class method overrides for drawPolyline and drawPolygon, for example, except for those in subclass Class DebugGraphics, which in turn call Graphics.drawPolyline and Graphics.drawPolygon - for example - at the end of the method implimentation anyway.
And besides, DebugGraphics is a swing class, and I would not be importing it in a strictly AWT application anyway.
So where is the actual code for these methods is what I am wondering?
Thanks;
~BillThe Graphics class is subclassed in JVM specific classes since rendering
graphics on different machines is going to be done differently (this
was discussed recently). So to use these methods find a suitable object
(like an image already loaded) and call getGraphics on it. This will
return a Graphics object cast from the JVM specific graphics subclass...
Steve -
We have entity classes that we use to access our database. We have subclasses derived from these entity classes that apply business rules. For instance, the base class AddressEntity has a
setAddress2(string) that AddressEntity.select() uses to set a class variable with data retrieved from the database. The derived class Address also has a setAddress2(string) method that puts restrictions on the length of the data. I want the AddressEntity.select() method to use the base class method AddressEntity.setAddress2(). I've tried using this.setAddress2() in AddressEntity.select() but the derived class method is still used. Any suggestions?
Thanks,
JoeIf you need to call some methods on the base class sometimes and some methods on the derived class other times, but using the same object, then yes dubwai is right you should revisit your Object hierarchy.
One simple way to do what you are asking is to have your method(s) look like this:
void setAddress2(String sAddress) { setAddress2(sAddress, true); }
void setAddress2(String sAddress, boolean bRestrictLength) {
// real method
}then you could just look at the variable bRestrictLength to see if you need to restrict the length, and have it default to true. In this way you can use overloading to solve your problem. -
Hi,
We've got an abstract base class (StringBase) which various types of strings inherit from. The copy constructor for this base class is private, since we don't want to allow copying when this class shouldn't be directly instantiated. A number of our methods take specify the base class as a reference, but take a derived class temporary as a default argument (see code appended).
This worked fine in 12.3, but in 12.4 beta, this now says:
Error: StringBase::StringBase(const StringBase&) is not accessible from __dflt_argA().
This works fine in clang and gcc, and indeed, this GNU document says it was a bug which was fixed in gcc 4.3.0:
Copy constructor access check while initializing a reference
which references http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#391
It only appears to error when the "-g" option is used, however, which doesn't seem right, and compiles fine if the "-g" option is removed, which makes me think it's a bug. Presumably the optimizer is eliding the copy when not using -g, but it's left in for debug mode, causing the compile error?
Many thanks,
Jonathan.
$ clang++ -std=c++11 defaultarg.cpp
$ g++ -std=c++11 defaultarg.cpp
$ /opt/SolarisStudio12.4-beta_mar14-solaris-x86/bin/CC -c defaultarg.cpp
$ /opt/SolarisStudio12.4-beta_mar14-solaris-x86/bin/CC -g -c defaultarg.cpp
"defaultarg.cpp", line 6: Error: StringBase::StringBase(const StringBase&) is not accessible from __dflt_argA().
1 Error(s) detected.
$ cat defaultarg.cpp
#include "stringbase.h"
#include "conststring.h"
static const ConstString S_DEFAULT("default value");
void SomeMethod( const StringBase& str = S_DEFAULT )
(void) str;
int main( void )
SomeMethod();
$ cat stringbase.h
#ifndef STRINGBASE_H
#define STRINGBASE_H
class StringBase
protected:
StringBase() {}
private:
StringBase( const StringBase& );
#endif
$ cat conststring.h
#ifndef CONSTSTRING_H
#define CONSTSTRING_H
#include "stringbase.h"
class ConstString : public StringBase
public:
ConstString() {}
ConstString( const char* ) {}
ConstString( const ConstString& );
#endifThanks for reporting the problem!
This looks like a compiler bug, I think an artifact of creating a helper function for the debugger for the default argument.
I have filed bug 18505648 for you. -
Using base classes for common attributes
Can TopLink handle use of non-mapped abstract base classes? There are a number of fields that are common to each and every one of my domain objects which, following good OO design principals, are moved up to a common superclass. So I have:
public abstract class AbstractDomainObject
private Integer id;
private Date dateCreated;
private Integer creatorId;
private Date dateModified;
private Integer modifierId;
// ... appropriate attribute accessors
Then a concrete class which gets mappped in Workbench:
public class Address
extends AbstractDomainObject
... specific attributes
I tried mapping all the specific attributes explicitly defined in the Address class and then using "Map Inherited Fields > To SuperClass" in Workbench. However, when attempting to test my mappings in the SessionConsole, only the attributes explicitly defined on Address are present in the SELECT clause.
Can what I am trying be done? If so, how?Steve,
What you are trying to do is very common and the process you described is exactly how map the class. I will summarize a couple of points for mapping this scenario.
1. You only need to import Address in and map it. If AbstractDomainObject is imported into the Mapping Workbench make sure that it is disabled. The abstract class is only required on the project's CLASSPATH.
2. You should not enable inheritance for the Address class. Inheritance is for situations where the abstract base class has its own independent table. I am assuming that your Address class has its own table that contains fields for all of the attributes it needs along with those of the abstract base class.
Assuming these conditions are met then TopLink will work fine with you Address class just as if it had all of the inherited attributes directly.
If you are still having trouble take a look through your generated project (XML or Java) to ensure that mappings exist in Address for All attributes. If the project looks good then I am at a loss. Customers have been using this pattern of use for over 5 years with TopLink and Java inheritance.
Cheers,
Doug -
Abstract/ concrete class questions/problems
I am new to java and working on a abstract problem. I'm getting several errors. Here is the code I have so far for the abstract class. I commented out the super and it compiles but I'm not sure if it correct. I'm suppose to create a abstract base class Animal. Single constructor requires String to indicate type of animal which then is stored in an instance variable. I also have to add a few methods (describe(), move(), etc).
public abstract class Animal
public Animal(String type)
//super(type);
public abstract String describe();
public abstract String sound();
public abstract String sleep();
public abstract String move();
}thanks for the replies. I modified my code but I have a few more errors I can't figure out. Can you browse the code and help point me in the right direction.
Here are the errors I get
cannot find symbol
symbol : constructor Cat(java.lang.String,java.lang.String)
location: class Cat
cannot find symbol
symbol : constructor Robin(java.lang.String)
location: class Robin
abstract base class:
public abstract class Animal
String type;
public Animal(String type)
this.type = type;
public abstract String describe();
public abstract String sound();
public abstract String sleep();
public abstract String move();
}concrete class
public class Cat extends Animal
private String name;
protected String breed;
public Cat()
super("Cat");
public String describe()
return new String(",a breed of Cat called");
public String sound()
return new String("Meow");
public String sleep()
return new String("Kitty is having purfect dreams!");
public String move()
return new String("This little Kitty moves fast!");
}another abstract class
public abstract class Bird extends Animal
protected String breed;
public Bird()
super("Bird");
public abstract String move();
}here is the abstract test program itself
public class AbstractTest
public static void main(String[] args)
Cat cat = new Cat("Kitty", "Angora");
Robin bird = new Robin("Rockin");
System.out.println("Form the cat: ");
System.out.print("This is: "); cat.describe();
System.out.print("Sound: "); cat.sound();
System.out.print("Sleeping: "); cat.sleep();
System.out.print("Moving: "); cat.move();
System.out.println("\n");
System.out.println("For the robin: "); bird.describe();
System.out.print("This is: "); bird.sound();
System.out.print("Sound: "); bird.sleep();
System.out.print("Moving: "); bird.move();
System.out.print("\n");
System.out.println("nEnd of program.");
} -
Base classes with Collection attributes
I have a question. Suppose I have a base class A, an abstract base class
to be exact, and subclasses B and C. Assume A has an attribute of
Collection type, let's call it collectionImpl. Now I would like subclasses
B and C to be able to have elements of different types along the lines of
what I've outlined below.
Strictly speaking, class A wouldn't have to be PC, since I primarily care
of B and C but I wanted to show the structure.
<class name="A" persistence-capable-superclass="A">
<field name="collectionImpl">
<collection element type="someType"/>
</field>
</class>
<class name="B" persistence-capable-superclass="A">
<field name="collectionImpl">
<collection element type="someOtherType"/>
</field>
</class>
So, how would one express this?
ScottUnderstood. Now for bit more clarification. Given my earlier example, what
if classes A, B and C implement the java.util.Collection interface. Does
Kodo have in issue with that? I know Kodo has this ProxyCollection stuff
but I don't really want to do that, nor do I think I really need to given
what I'm trying to accomplish.
The issue I'm having now is that the Kodo Enhancer is complaining that no
element-type is declared when I have an attribute of class type B for
example (implementing java.util.Collection) even though an element type is
declared for the that actual Collection object held in the base class of B
(A).
<class name="A" requires-extent="false">
<field name="impl">
<collection element-type="SomeType"/>
<extension vendor-name="kodo" key="ordered" value="true"/>
</field>
</class>
<class name="B" persistence-capable-superclass="A"
requires-extent="false"/>
Class "A" extends java.util.AbstractSet, impl is an instance of
java.util.Collection.
All this was working quite well until I made some updates recently
although the basic implementation is the same. Logically I don't know what
I might have done to cause the new error message.
I'm using v2.5.2 BTW.
Scott
Stephen Kim wrote:
The one thing to note is that if you do not make A persistent capable,
you cannot persist fields -declared- in A or query starting from A.
Scott A. Leschke wrote:
Can I acheive the same effect by making A be non-PC and provide a abstract
protected method that will be used by a to access the collection
implemented in the sub-classes as you suggest (ie. Collection
getCollectionImpl())?
Steve Kim
[email protected]
SolarMetric Inc.
http://www.solarmetric.com -
How to call a method of a base class if the base class is abstract...
This is my sample code>>>>
abstract class b {
public void display() {
System.out.println("I am in Base Class");
class test extends b {
public static void main(String[] args) {
test obj = new test();
obj.display();
public void display() {
System.out.println("I am in Derived Class");
I want to call base class version of display with derived class object.........is it possible....* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
* headdesk *
Enough with the friggin' zombie threads already! -
Explizit using methods of base class
when using a base class reference from an abstract class A and creating an object of subclass B
A ref_A = new B();
assuming we have implemented the method m() in A and B, then
ref_a.m()
calls Method m of subclass B
(dynamic binding, fine)
Is there a possibility to force explicitely the call of method m of superclass A.
(i mean not a call from Method m in B with super())are you absolutely sure ?I am sure. Perhaps you are thinking of C++ (and if you're not, I am!) where you can write: ref_A.A::m(),
but there's no way from the client code to do that in Java. If you really need to do this, your
design of A should reflect it:
public abstract class A {
public final void mOldSchool() {...}
public void m() { mOldSchool(); }
public class B extends A {
public void m() {...}
}I agree with Kayaman, though: question your design. In the abstract, this is a shakey design. -
Calling a method from an abstract class in a seperate class
I am trying to call the getID() method from the Chat class in the getIDs() method in the Outputter class. I would usually instantiate with a normal class but I know you cant instantiate the method when using abstract classes. I've been going over and over my theory and have just become more confused??
Package Chatroom
public abstract class Chat
private String id;
public String getID()
return id;
protected void setId(String s)
id = s;
public abstract void sendMessageToUser(String msg);
Package Chatroom
public class Outputter
public String[] getIDs()
// This is where I get confused. I know you can't instantiate the object like:
Chat users=new Chat();
users.getID();
I have the two classes in the package and you need to that to be able to use a class' methods in another class.
Please help me :(I have just looked over my program and realised my class names are not the most discriptive, so I have renamed them to give you a clearer picture.
package Chatroom
public abstract class Chatter
private String id;
public String getID()
return id;
protected void setId(String s)
id = s;
I am trying to slowly build a chatroom on my own. The Chatter class is a class that will be used to represent a single logged in user and the user is given an ID when he logs in through the setId and getID() methods.
package Chatroom;
import java.util.Vector;
public class Broadcaster
private Vector<Chatter> chatters = new Vector<Chatter>();
public String[] getIDs()
// code here
The Broadcaster class will keep a list of all logged-in users keeps a list of all the chats representing logged-in users, which it stores in a Vector.I am trying to use the getIDs() method to return an array of Strings comprising the IDs of all logged-in users, which is why im trying to use the getID() method from the Chat class.
I apologise if I come across as clueless, it's just I have been going through books for about 4 hours now and I have just totally lossed all my bearings -
Where to put javascript code?
Hello,
I am trying to set some columns in a list as "read-only" and is using the following code:
<script type=”text/javascript”>
function SetReadOnly()
var elements=document.getElementById(’4_ctl00_ctl00_TextField’);
elements.readOnly=true;
_spBodyOnLoadFunctionNames.push(“SetReadOnly()”);
</script>
But I am not sure where to put the code in. Should I put it in the space in Content Editor Web Part,
or through a link to a txt file, or in "Edit HTML"? I've tried them but none works.
Thanks a lot!
PatrickYou can try this:
1) Open your Sharepoint List. Go to List edit view.
2) On right side of Ribbon you will find "Form Web Parts" option as shown in figure.
3) Choose your List form which you want to edit.
4) Now you can add web part in new window.
5) Add Content Editor Web part.
6) In content editor web part add the path of your "txt" file in which you have written your script, for eg.
<!DOCTYPE html>
<html>
<body>
<script type=”text/javascript”>
function SetReadOnly()
var elements=document.getElementById('4_ctl00_ctl00_TextField');
elements.readOnly=true;
_spBodyOnLoadFunctionNames.push("SetReadOnly()");
</script>
</body>
</html>
I haven't tried this method so I am not sure but hope it works...:D
***If my post is answer for your query please mark as answer***
***If my answer is helpful please vote***
Maybe you are looking for
-
Both my firewire ports won't recognize a dang thing. They've just stopped. I go to the profiler and it says: FireWire Bus: Maximum Speed: Up to 400 Mb/sec Does that mean they're alive?! I've tried the powering down (totally disconnecting everything f
-
Hi! pls help date functions
hi! i have problem in date functions in java! 1. if i give input date format is dd/mm/yyyyy (or) yyyy/mm/dd (or) mm/dd/yyyy? the result must be display dd/mm/yyyy only? pls help me! thanks and regadrs senthilraj
-
FB4 Beta 2: Stopped working today. Is that intentional?
Hello, I have 47 days left on my beta2. It worked yesterday, but not today. Is that intentional?
-
Shared Services database content not found in the specified database - EPM
I installed three VM machines (Workstation) for the following on Windows 2003 OS: VM1 : Oragle DB 11g, Shared Services. Workspace VM2 : Financial Management, EPMA, Calc Manager VM3 : Microsoft Active Directory I have configured Database and Shared se
-
Pages printing in draft mode. First line normal and the rest is faint. Please, how do I reset this. Thanks Bruce