When not to inherit?
I was going across a paper when I stumbled across this line
"Inheritance is the most widely misused phenomenon in OO pragramming"
I was a bit shocked to read this and have been wondering since as when and why to inherit or not to inherit?
So the question is to inherit or not to inherit and what are the other options if two classes have an is a relationship.
People in C++ tended to use inheratance as a way to include a header file. Many of them came from C backgrounds, and they'd really have no understanding of the meaning of Object Orientation. They just realized, if they extended Class this, and Class that, they had access to all of the methods and functionality of those two classes. This is pretty much a sin in Object Oriented programming. You only extend an object, if you ARE a type of that object. A Wheel is NOT a Nut, or a Bolt. However, you may want to add such functionality to a wheel. Say, you had a Wheel, and you wanted to add the function "Tighten bolt" to it. You could achieve this functionality by extending the Bolt class that you made, which has a "tighten bolt method", and then when you called such a method, it would produce the functionality of changing some members which are now part of your wheel class to reflect the bolt having been tightened. This may seem to make sense, but from an Object Oriented stand point it doesn't. A Wheel HAS bolts, it isn't a Bolt itself. There for, in the wheel, you'd create bolt object, and then if you wanted to tighten a bolt on the wheel, you'd have to negotiate that through the wheel object. You should only inherit, if you are actualy a type of that object, otherwise you should use Interfaces to make the interaction with that Bolt abstract. There are many kinds of bolts, perhaps they'd act differently under certain condotions, but the Wheel class doesn't have to care about that, as long as that Bolt has a "Tighten Bolt" method. So, when in doubt use an interface.
-Jason Thomas.
Similar Messages
-
When to use inheritance and when not to?
I've just been trying find out when to use inheritance and when not to use inheritance? I know that inheritance gives advantages such as code reuse and maintainability. But when are their times not to use inheritance that may effect the design of a project?
Also when should one consider aggregation over inheritance(is-a relationship)?
thanks,
plandisHi
Answering this question usually requires a few books, so, I'm sorry, it's not really as simple as choosing between using a screwdriver vs. a hammer.
But, very short, inheritance should ideally only be used when there exist a strict 'is-a' relationship. However, sometimes it may be clever to inherit when you have a 'is-almost-a' relationship... And sometimes this is a stupid move. This depends on the context/circumstances.
Aggregation is normally considered a 'has-a' relationship, thereby differing clearly from inheritance. The old 'car' model says "a car is-a vehicle and has-some (at least) wheels."
The wheels are aggregated to the car class, that itself is inherited from vehicle.
However, this is just a good rule-of-thumb and there may be circumstantial reasons for not following these guidelines. -
This is a repost to correctly ID this as a Spaces issue. I am using a MacBook Pro with a second monitor in extended desktop. I put iMovie in full screen and when I put it back, it disappeared off of both desktops. I can see it in Spaces and I can use it in full screen. However, it is not available when not in full screen. When I drag and drop it in Spaces to a desktop, it animates off of the top of the screen versus landing on that desktop. I have tried to change the application assignment by right clicking on the iMovie Icon > Options > Assign To, but it affects nothing. I have rebooted both with the external monitor and without, I have uninstalled and reinstalled iMovie and I have tried many combinations of screen resolutions and it is still assigned somewhere other than a desktop. It appears to no longer be associated with or assignable to a desktop. Anyone have any ideas?
Can you access iMovie without being in fullscreen when you do not have an external monitor connected? I cannot. No matter the monitor configuration, it is only accessible in full screen for me.
I agree - it is for sure a bug. -
Re: [iPlanet-JATO] Re: session timeout when not submitting to a handler
Mark--
I know what's happening here, but am curious about your approach. You said
in an earlier email that you were generating links directly to JSPs, but
from what you are describing, you are generating JATO-style links to access
JATO pages. Nothing wrong with that, but there is a signficant difference.
Actually, it just occurred to me, I'm wondering what your URLs look like.
The way the request dispatching works in JATO is it ignores anything after
an initial "." in the final part of the URL path. For example, a request
for "/myapp/module1/MyPage.jsp" doesn't actually try to hit the JSP, instead
it tries to hit the JATO page "/myapp/module1/MyPage".
The end result is that you may think you are accessing a JSP directly, but
are instead accessing a JATO page. The reason the request dispatching works
this way is because it is illegal to access JATO JSPs directly, and there is
actually a (disabled) JATO feature that piggybacks on the use of the
dot-delimited URL.
So, now I need to understand your intent. I wasn't really sure why you were
generating direct JSP/page links to begin with. This works against the Type
II architecture JATO uses, in which all JATO requests go back to the
controller servlet.
If you are trying to design something like a menu page, you may have thought
that it was burdensome to create a number of HREF children, plus implement
event handlers for each of them. This definitely would be burdensome beyond
just a handful of links, but this is why JATO provides other mechanisms for
doing what I'll call here "polymorphic HREFs".
Assuming this menu page scenario, the easiest thing to do is to simply use
one HREF child on the page, and add a value to it each time it is rendered
that distinguishes it from the other instances on the page. In your event
handler for the HREF, you simply check this value and use it to decide which
page to forward to. You can add a value to an HREF or Button by using the
"addExtraValue()" method. Or, if you are using JATO 1.2, you can add extra
query string NVPs right in the JSP document using the "queryParams"
attribute of the <jato:href> tag. Thus, your one HREFchild and event
handler become "polymorphic" because what they do depends on the context in
which they are invoked.
Now, I still don't have confirmation that this is what you were trying to
do, so until I do, let me explain the exception you're seeing. JATO assumes
that when a request comes in for a page that includes the pageAttributes
NVP, it is a request coming from a previously generated JATO page. Because
of the way JATO works, this means that the request dispatching code should
send the request back to the originally rendered page. For example, if Page
A renders an HREF, which the user then activates, JATO sends the request
back to Page A for handling. All of the HREFs and forms generated during
rendering of Page A actually refer back to Page A, regardless of where those
links or buttons actually pass the request in their event handlers/Command
objects.
So, what's happening when you include the pageAttributes in your HREFs is
that JATO is assuming that a request is being sent to the target page, with
the assumption that the target page has a mechanism in place to handle the
request. This assumption relies on the specification of the "originator" of
the request being specified in the request. For links/HREFs, the name and
value of the HREF is sent along with the request. For forms, the name and
value of the button that was pressed are sent in the request. JATO uses the
presence of these name/value pairs to decide which event handler, or which
Command object, to invoke to handle the request.
The exception you are receiving is saying that there was no object on the
target page that indicated it could handle the request. This is to be
expected, since you have not specified a query parameter that indicates
which CommandField child is responsible the request. However, this is where
I see the disconnect, because that is not what I believe you were trying to
do (as explained above).
So now, given all the information above, can you tell me what you're trying
to accomplish, and whether or not the info I've given you has helped you to
design a mechanism more in line with a JATO approach? If not, given that I
understand what you're trying to do, I can offer a more concrete solution.
Todd
----- Original Message -----
From: <Mark_Dubinsky@p...>
Sent: Monday, November 05, 2001 2:54 PM
Subject: [iPlanet-JATO] Re: session timeout when not submitting to a handler
This is the exception we get:
(And BTW, leaving a blank value for the pageAttributes doesn't help)
[05/Nov/2001 17:49:18:4] error: <portalServlet.processRequest>
javax.servlet.ServletException: The request was not be handled by the
specified handler
at java.lang.Throwable.fillInStackTrace(Native Method)
at java.lang.Throwable.fillInStackTrace(Compiled Code)
at java.lang.Throwable.<init>(Compiled Code)
at java.lang.Exception.<init>(Compiled Code)
at
javax.servlet.ServletException.<init>(ServletException.java:107)
at
com.putnaminvestments.common.jato.ApplicationServletBase.dispatchRequ
est(Compiled Code)
at
com.putnaminvestments.common.jato.ApplicationServletBase.processReque
st(Compiled Code)
at
com.putnaminvestments.bp.portal.portalServlet.processRequest(Compiled
Code)
at
com.putnaminvestments.common.jato.ApplicationServletBase.doPost(Compi
led Code)
at
com.putnaminvestments.common.jato.ApplicationServletBase.doGet(Compil
ed Code)
at javax.servlet.http.HttpServlet.service(Compiled Code)
at com.putnaminvestments.bp.bpServletBase.service(Compiled
Code)
at javax.servlet.http.HttpServlet.service(Compiled Code)
at
com.netscape.server.servlet.servletrunner.ServletInfo.service(Compile
d Code)
at
com.netscape.server.servlet.servletrunner.ServletRunner.execute(Compi
led Code)
at com.kivasoft.applogic.AppLogic.execute(Compiled Code)
at com.kivasoft.applogic.AppLogic.execute(Compiled Code)
at com.kivasoft.thread.ThreadBasic.run(Native Method)
at com.kivasoft.thread.ThreadBasic.run(Native Method)
at com.kivasoft.thread.ThreadBasic.run(Native Method)
at com.kivasoft.thread.ThreadBasic.run(Native Method)
at com.kivasoft.thread.ThreadBasic.run(Compiled Code)
at java.lang.Thread.run(Compiled Code)
--- In iPlanet-JATO@y..., "Todd Fast" <Todd.Fast@S...> wrote:
Mark--
Initially we tried to add the pageAttributes NVP as well, but that
was
causing an exception, so we stopped doing that.That's odd--what was the exception?
Our problem now is that when the SessionTimes out it does not go
to
onSessionTimeout method as in processRequestMethod of the
ApplicationServletBase it looks for pageAttributes. If it is notnull
then only onSessionTimeOut method is called.This is sadly the only technique for determining if a session hastimed out
and a new one been created, versus the initial creation of thesession.
Is there any work around for this? Maybe you can suggest how topass
the pageAttributes without causing the initial exception?Definitely--let me know what the exception was and I'll be able tosuggest
something. However, it shouldn't really be any harder thanappending a
"jato.pageAttributes=" empty NVP on the HREF.
Todd
Todd Fast
Senior Engineer
Sun/Netscape Alliance
todd.fast@s...
For more information about JATO, please visit:
http://developer.iplanet.com/tech/appserver/framework/index.jspOK, here's what I'm trying to do: We have, like you said, a menu
page. The pages that it goes to and the number of links are all
variable and read from the database. In NetD we were able to create
URLs in the form
pgXYZ?SPIDERSESSION=abcd
so this is what I'm trying to replicate here. So the URL that works
is
pgContactUs?GXHC_GX_jst=fc7b7e61662d6164&GXHC_gx_session_id_=cc9c6dfa5
601afa7
which I interpreted to be the equivalent of the old Netd way. Our
javascript also loads other frames of the page in the same manner.
And I believe the URL-rewritten frame sources of a frameset look like
this too.
This all worked except for the timeout problem. In theory we could
rewrite all URLs to go to a handler, but that would be...
inconvenient. -
JInternalFrame not opening in JAR file, but works when not in JAR
I have a folder that contains multiple .class files. I make all the class files into one jar file with this command:
jar cmf mainClass.txt myapplication.jar *.class
The mainClass.txt contains the following:
Main-Class: myapplication
class-path: myapplication.jar
The myapplication.class opens up a JDesktopPane inside a JFrame. It also contains a start menu, which again has elements that opens up misc JInternalFrames inside the JDesktopPane. The problem is this:
When I run the application from a .bat file, everything works fine. However, after making the JAR Executable file, everything works except 1 JInternalFrame. Now, the code for this JInternalFrame is far too much to post, so I'll have to ask as follows;
Are there any reason why a JInternalFrame would not work from inside a JAR Executable, but work when not in the JAR file? Especially when other JInternalFrames are working? What can make 1 JInternalFrame different from the others in this regard?Perhaps the problem lies somewhere else.
Obviously if other JInternalFrames are working then there is a difference in the one missing internal frame that causes it not to show up.
My guess is that perhaps you are missing one or two classes in your JAR that are used by that JInternalFrame and that an exception is being thrown causing it not to show.
Double check the contents of your JAR and make sure that all the classes are present and that they are the right versions. -
Should I turn off my Mac Pro when not in use or leave it running?
I have been told I should never turn off my computer by some people, and others say that I should always turn it off when not in use! I use my Mac Pro primarily for music recording/editing in my home studio or word processing. Now that I have an iPad I use that for web browsing, email, FBing, etc. and I find myself on my Mac Pro a lot less. I get the basis behind both trains of thought; those who leave it on feel always stopping and starting up puts unnecessary wear on the moving disks, and those who shut down think if the parts are always moving they are bound to wear out faster. I am not as concerned with conserving power as I am with keeping my machine safe! If you have any information on this topic I would love to hear it. Thanks!
Providing you have a robust firewal and are not worried as a result about being hacked then leave it turned on and allow it to sleep. Make sure you allow the screen to sleep as well a that is the item that is more prone to damage by being left on all the time.
I never turn my machine off, never have with any of my Macs ever since my first one back in 1979-ish and have never suffered any adverse affects. Today, the power drain is so small when allowed to sleep that I doubt they would offend even the ardent 'turn off everything and pull out the plug to save the planet' person.
If you have an iPad or iPod synced with the Mac for email and iCal and address Book etc. then if you leave it on it should be up to date as soon as you return home, mine is anyway. With iCloud coming out very soon that may come into play even more so with all its advance pushing etc. Just a thought.
One advantage in leaving the machine on (sleep) is that you can access it from anywhere in the world should the need arise with the appropriate settings, which you can't if you turn it off.
Leave it on. -
How do I turn off background ni file activity when not using Labview? I use labview rarely, and I also use my computer for demanding multimedia applications, including multitrack digital audio recording. I need to reduce as much background activity as possible, and taking a look with task manager I see files such as nimxs.exe, nipalsm.exe, nipalsm.exe, nisvcloc.exe, and nicitdl5.exe running even when I haven't used Labview (8 I believe). These files run even after I right click the NI icon on the lower right and turn off the application. I would like the computer to boot up without these files, and for the necessary files to be activated only when I start the program.
Can this be done or do I have to remove labview from the system to improve performance?
ThanksHello, those processes are part of running NI services that start when Windows boots. These processes serve varied purposes and stopping them can have undefined and unknown consiquences for your NI products. These products run at "normal" priority meaning that they should be preempted by any process running at a higher priority which I would expect your other application to be doing given their time sensitivity. That being said, in Windows XP (I can't speak for other OSes), you can lower their priorities even greater through task manager (right click the process»set priority) to further remove them from contention for resources. If you want to prevent them from running you can set the service startup type to "manual" in Control Panel»Administrative Tools»Services. Right click the process go to Properties and Under the General tab choose Startup Type»Manual. This will start up the processes only when something directly starts it up. LabVIEW will start these processes up as it attempts to use them. When you shut down LabVIEW you will need to manually shut down these processes through task manager. Again, doing this can cause problems with your NI products on your system and it is not advised.
Travis M
LabVIEW R&D
National Instruments -
Get error message: "Element 'when' not found in 'xsl:choose'"
Thank you in advance for your help.
I got this error message:
Caused by: oracle.xdo.parser.v2.XMLParseException: Element 'when' not found in 'xsl:choose'.
When I put a form field with this help text:
<?CHOOSE:?><?WHEN:ELMT_CATEGORY_CODE='SS'?>
Did some research but cannot find why...
-BillNever mind, put the <?end choose?> in wrong position. Thanks
-
Why would my iPod show a full battery when connected to power but when not connected it will no longer turn on
For both
Try:
- iOS: Not responding or does not turn on
- Also try DFU mode after try recovery mode
How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
- If not successful and you can't fully turn the iOS device fully off, let the battery fully drain. After charging for an least an hour try the above again.
- Try on another computer
- If still not successful that usually indicates a hardware problem and an appointment at the Genius Bar of an Apple store is in order.
Apple Retail Store - Genius Bar -
I have downloaded all my music from the cloud to my new iPhone and created playlists so I can listen to it when not it wifi like when on a plane. If I turn on iTunes Match will I still have this music still downloaded? The online information suggests all my music will be replaced. Will I have to download it again??
What you have on your computer is your iTunes library, not an iTunes "account." The account that is related to iTunes is your Apple ID, which you use to sign in to the iTunes Store and make purchases. It is also used with iCloud. iPods (that are not iPod touch) are associated with your iTunes library, not to your Apple ID.
So, I think you probably just need to set up (or update) automatic syncing for the iPod. If it's not set up to sync those new songs, iTunes still syncs the iPod, but it syncs nothing
In iTunes, if the sidebar (along left side of iTunes window) is hidden, from the menu bar, under View, select Show Sidebar. In the sidebar, the iPod appears under DEVICES, when it is connected.
Select the iPod in iTunes. There is a row of buttons, starting with Summary. Click on Music next to Summary. This is the iPod's Music screen, where you tell iTunes how to sync songs to the iPod.
Check the box for Sync Music (if it's not already checked). If your iTunes music library fits completely on the iPod, you can choose to sync Entire music library. Otherwise, you can choose to sync Selected playlists, artists, albums, and genres. On the lists below, checkmark the playlists, artists, albums, and/or genres that you want on the iPod. When you click Apply, the songs from your selection sync to the iPod.
One convenient way to set this up (if you can't sync the entire iTunes music library) is to create a new playlist in your iTunes library. Name it "iPod Songs" (or whatever you want). Put ALL songs that you want on the iPod on this playlist, including those new songs. Back on the iPod's Music screen in iTunes, select this playlist under Playlists. Going forward, to update songs on the iPod, just update that playlist in your iTunes library (add/remove songs). The next time you connect the iPod (or click the Sync button), iTunes automatically syncs the same changes to the iPod. -
How do I keep an application window hidden when not accessed?
I have an application running constantly to control my FW audio interface outputs etc. I use system events applescripts to control it's UI with a USB controller (PowerMate) - and that by necessity brings the application window to the front every time accessed. That's fine.
But I want to have a script that hides this application window when it's not used after 2 seconds. Maybe there is an "on idle" script that could run to check if that window is visible. I imagine something including lines like this:
-- a routine that checks if the window is visible every 2 seconds or so.
-- the window reference
window "Studio Monitor Express" of application process "Studio Monitor Express"
-- if it is, then hide it
-- for hiding the window/app
keystroke "h" using command down
-- if it's not, then ignore
I'm not sure whether to use system events or finder events etc. I have a bunch of other apps running obviously, but I just want this particular window to disappear when not needed.I solved it. I know. Easy:
on idle
tell application "System Events"
set visible of process "Studio Monitor Express" to false
end tell
return 2
end idle -
I just got the 5G Airport Extreme base station. Set-up was a snap! Maybe 10-15 minutes compared to a friend who got another name brand for his pc and took a couple hours, even having to call customer support! Been working great so far, but am concerned about never turning it off, not only about the possibe harm that could be done to the unit, but also about having an active, open Internet connection 24/7. Before I got my Airport Extreme I was using Ethernet cable with a cable modem that could be placed on "standby" whenever I was not using my Mac for Internet, but since AE5G doesn't have a power switch on the unit, have left it turned on rather than unplugging it by the electrical cord. I did turn AirPort "off" in the menu bar when not using it wth my Mac, but AE is still apparently constantly active, showing a steady green light. Would there be any harm done by plugging it in only when I want to use Wi-Fi, then unplugging it?
Thanks for the help!Would there be any harm done by plugging it in only when I want to use Wi-Fi, then unplugging it?
That is a matter of debate, since there are two schools of thought regarding power status on a router.
One school maintains that you can turn the device on and off as needed. Makes sense for some folks. The advantage of this is that it might save a bit of electricity, although the Extreme draws very little power most of the time.
Another school believes that there is a reason why Apple did not even place an "Off" switch on the device. It's designed to run 24/7.
Leaving the Extreme on will place far less stress on the electrical components in the device since they stay in an "idle" state most of the time, drawing very little current. Powering any electrical device up sends a sudden rush of current through the device, which places far more stress on a device than if it is simply left on.
It depends on your priorities. If you want to save electricity, your decision is already made. If you intend to prolong the life of the router, then consider leaving it on, as Apple intended.
A compromise position might be to leave the Extreme on most of the time and power if off for long weekends or vacation periods when you will be away. Remember that the Extreme must establish all new network connections every time that it powers back up....perhaps another reason to simply leave it on. -
I am very new to LR5. I have LR5 set up so that my catalog and photos are on an external hard drive. I found out that when not connected to the hard drive, LR5 cannot find my catalog, therefore, I cannot do any editing in smart previews unless connected to the external hard drive. How can I fix this issue so that I can edit photos without being connected to the external hard drive. Is there a way of copying the catalog off the hard drive on the computer hard drive or do I need to reestablish a new catalog using LR5? Does the catalog always need to be loaded on the hard drive? Thank you in advance.
Yes that is correct. The LR catalog must be on the computers internal drive. Then when you have Smart Previews enabled you can edit image without having the drive they are on connected. Then when you connect that drive the images will be updated.
Just COPY those 4 folders over to your internal drive to a folder called Lightroom Catalog that you create. Then Open LR and go to the File menu item and select Open Catalog. Browse to the folder you created called Lightroom Catalog and select the Lightroom 5 Catalog.lrcat file and click Open. Once Lightroom restarts open the preferences, Edit>Preferences, and on the General Tab in the Default Catalog section make sure "When starting up use this catalog:" area lists where you have copied those folders. Something like Macintosh HD/Wherever you created that folder/That folder name/Lightroom 5 catalog.lrcat. -
I'm trying to install a samsung series 7 750 monitor for use with my mini mac. When I plug the computer to the monitor I get a blank screen, no picture. When not plugged in to the computer the screen is black and a square displAys that says analog, HDMI 1, HDMI 2. Any ideas?
Hey there saraszeg,
It sounds like you are trying to use an external monitor with your Mac Mini but cannot get more than a gray screen. You can use the following steps to help troubleshoot the Mac side of things here:
Apple computers: Troubleshooting issues with video on internal or external displays
http://support.apple.com/kb/HT1573
Remove all display cable extenders, KVM switches, or other like devices and retest to determine if the issue is resolved.
Try unplugging the video adapter or cable and then plug it back in.
If more than one video adapter is in use (or "daisy-chained"), troubleshoot by using only one adapter.
Example: A mini DisplayPort to DVI adapter connected to a DVI to HDMI adapter is an unsupported configuration because there is a series of adapters in use.
If available, try using a different display and or adapter (or use a different connector by using DVI instead of VGA, for instance).
Reset the system
You can reset the Mac's parameter RAM and SMC.
Reset the resolution
Start by resetting the Mac's parameter RAM. If the display does not come up, was previously set to an unsupported resolution, and still results in no video:
Start up in Safe Mode.
From the Apple () menu, choose System Preferences.
Choose Displays from the View menu to open the preferences pane.
Select any resolution and refresh rate that your display supports.
Restart your computer.
Thank you for using Apple Support Communities.
Take care,
Sterling -
Am I supposed to leave the display plugged in when not in use?
should the display be left plugged in when not in use? is it just like leaving the power cord to the MacBoold Pro plugged in when the computer is off?
thanksSure, you can leave the display plugged into the socket, provided you turn OFF the display itself. There must be somewhere some switch or touch button that will turn the display OFF.
Usually, those displays use a lot of power, so it's better to save
I shall add an unrequested piece of advice: if you don't this already, please use some kind of electrical surge protector
<http://en.wikipedia.org/wiki/Surge_protector> to connect your computer, display, printer, router, etc to the wall socket.
Maybe you are looking for
-
MB5B - Stock on posting date doesn't show Storage Location field
Hi All, I run report MB5B - Stock on posting date with Stock Types = Storage Loc/Batch Stock, but the report doesn't show Storage Location field in result. How can I see it in this report? Thank you very much for your kind support! Cao Huy.
-
Unity player won't use discrete graphics--plugin-container?
I'm trying to play a Unity game in Firefox--honestly because Chrome doesn't support them anymore. My computer is a Lenovo Y50 with an 860M graphics card running Optimus. I've set Firefox to use the discrete graphics card, but Unity games refuse to ut
-
CR2 files not recognized by CS6 or Bridge
My CS6 and Bridge don't recognize the raw CR2 files from my Canon 5D mark III. Everything is updated, I downloaded the latest plug in, what should my next step be to fix this? Thank you.
-
Songs have begun stuttering and skipping
I have a problem that predates my recent Windows 7 install. I have many, many songs that have begun to repeat the first few seconds two or three times before commencing, slightly skipping beats etc. It's almost as if the first few seconds have been d
-
Don't wanna album artworks keep floating on the main menu
Is there any way to disable album artworks keep floating on the main menu of iPod classic? I think Apple should give us a choice to disable this function with next iPod firmware update. Some album artworks I don't want to show up there. And the key p