I've been posting about Powerbuilder a lot lately. The PB application, I work with currently is actually an n-tier application written in PB, Java and JSP. The application is built around a middle tier from Sybase called Enterprise Application (EA) Server. It's also called Jaguar (which is actually a part of the EA Server). A quick search for EA Server in google brings up Electronics Arts page, a gaming site. Search on Jaguar brings up all kinds of other things. So, there is not a lot of help on EA Server, though Sybase's own site has a wealth of information on the product. In my current project, we rely on EA Server for all our business rules and multi-tier application support. I am learning about the product in an effort to improve our architecture and thus our application performance. I will my share my experiences here, so it can benefit others trying to learn or use the product.
EA Server is an Application Server like Oracle Weblogic, IBM Websphere, JBoss etc. It is a Java container like all others mentioned. EA Server is a full blown Java server, so it supports Servlet, JSP, EJB and JMS. Apart from that, it has a speciality of being able to run PB objects as well. With support for CORBA (IIOP) and COM (on windows machines) components, it enables PB developers to develop application modules in PB, Java, C++ that can talk to each other through CORBA. For e.g., we have a site built using JSP pages that "talk" to PB objects. Recently, I developed a wrapper in Java for PB classes, so our Coldfusion applications can use PB objects as well. With this setup, we are able to implement an n-tier application in various languages.
While researching the issues and figuring out new methods to improve our Server performance, I realized how powerful the server is. I currently work with EAS 5.5. The latest version is 6.4. In 6.x, Sybase rearchitected the product completely to be more Java centric. To be able to do that, they included a Jetty Java container and wrapped each PB object as a J2EE object, so everything runs as Java objects. I haven't tried this version yet, but it sounds interesting. Unfortunately, from what I heard, Sybase (SAP) is thinking of getting rid of this completely in a few years and re-architect PB support into SAP's Netweaver server. So, really the knowledge about EA Server may disappear in a few years. (This is exactly what happened to Forte! Is it my luck or what?).
Irrespective of the fate of the EA Server, I believe the techniques learned in this exercise will be useful with other servers as well. I am already, trying our web app in Apache Tomcat which can then connect to our PB objects running in EA Server. I will share these experiences here as well. So, if you are interested in EA Server or writing n-tier in PB or even how to make PB talk to Java components usingCORBA, please check back in.
Sunday, September 16, 2012
Quick Tip - Oracle SQL*Plus: HTML output
Recently, I posted about SQL*Plus, a database querying tool from Oracle. Like I mentioned there, the tool is rudimentary and has some basic file handling capabilities. It has a command, SPOOL, to write the console output to a file. Traditionally, you only spooled the output to a text file. Some releases ago (I believe in 8i), Oracle included option to spool the output in HTML format. Useful when you are dumping data from tables (Have you tried dumping table data in plain text file format??) and for generating simple reports.
To generate HTML output from SQL*Plus, all you have to do is add markup option either on command line or inside the script. By the nature of it, it is only useful when you are spooling the output. Just add below to the script before spooling: and the output will be spooled to the file mentioned in HTML format.
That's it. Just be aware that the output file will be larger than the usual text file spool. By the way, the hyphen "-" at the end of each line is the line continuation character in SQL*Plus. So, it's really one line command with several options.
Alternatively, you can specify the HTML option on the commandline as shown below:
The option -M "HTML ON" is equivalent to MARKUP HTML ON in the script above. The option, -S is for silent, which turns off spurious output from SQL*Plus.
See here for more about creating HTML reports using SQL*Plus.
To generate HTML output from SQL*Plus, all you have to do is add markup option either on command line or inside the script. By the nature of it, it is only useful when you are spooling the output. Just add below to the script before spooling: and the output will be spooled to the file mentioned in HTML format.
SET MARKUP HTM ON SPOOL ON PREFORMAT OFF ENTMAP ON -
HEAD "<TITLE>My TABLE Listing</TITLE> -
<STYLE type='text/css'> -<!-- BODY {background: #FFFFFF} --> -
</STYLE>" -
BODY "TEXT='#000FF'" -
TABLE "WIDTH='90%' BORDER='5'"
...
spool dump_table.html
...
SPOOL off
That's it. Just be aware that the output file will be larger than the usual text file spool. By the way, the hyphen "-" at the end of each line is the line continuation character in SQL*Plus. So, it's really one line command with several options.
Alternatively, you can specify the HTML option on the commandline as shown below:
sqlplus -S -M "HTML ON" <user>/<password>@<SID> @dump_table.sql > dump_table.html
The option -M "HTML ON" is equivalent to MARKUP HTML ON in the script above. The option, -S is for silent, which turns off spurious output from SQL*Plus.
See here for more about creating HTML reports using SQL*Plus.
Monday, September 3, 2012
My Journey with Ubuntu Contd - Switching Desktop
Last time, I posted about upgrading to Ubuntu 12.04, Precise Pangolin. It has a user interface (desktop) called Unity. It looked different from Gnome desktop I got used to in ver 10.x. It was an adjustment, but it was easy to get used to. One problem I had though was that it kept freezing up at random. I believe this is a bug in the interface, judging by the bug reports opened for the issue.
While researching the issue, I found out that I could replace my desktop interface easily with Gnome desktop I used to like!! This blew my mind!! What? Replacing desktop? You mean re-installing complete OS, right? At least, that's what I am used in the MS-Windows environment. No, not with Linux. Here is a link I used in getting the new desktop installed. This put Gnome right beside Unity. All I had to was switch to Gnome when I logged in (See Fig. 1). So far, it's working fine. Apart from this, my applications and settings are still there. It connected to network and printer right away, so I didn't miss anything. (Note: While logging in I had to use Gnome (No effects), to get the same desktop look I had in 10.x.).
[caption id="attachment_455" align="alignnone" width="274"]
Fig 1. Gnome in Pangolin[/caption]
(Note: to get to this list, click on the ubuntu icon
while on the login screen. This is like pressing F8 to get to Safe/Normal mode in MS Windows).
Coming from MS Windows environment, I didn't think this was possible*. Not that I am a Micorsoft basher or anything. I've worked on MS Windows, most of my working career. I believe, MS-Windows is part of the evolution process a lot of us went through in the Software industry. Even so, I couldn't avoid being disappointed with MS-Windows. First of all, there is no such option with MS-Windows. With windows, if you wanted a different desktop, you would have to reinstall different version of OS. Remember Vista? When it came out it was buggy. Microsoft offered that you could "downgrade" to XP one time. But then, you lost the shiny new OS called Vista. On top of that, when I switch to a new OS like that, I am sure to face an issue or 2 to get it to work with the set-up I have. No, this was not supposed to be possible.
(Note *: There were some custom desktops available from 3rd party, but nothing fitted in smoothly, as Gnome did here! Further, they typically ran on top of the existing windows desktop, so they were slower).
So, I researched this a bit more. Apparently, Ubuntu (actually any linux and Unix) OS is built in a modular way. One layer can be easily replaced without disturbing another. As you know, underneath it all, there is kernel, the core shell in the OS. Then there is command line interface which is what we were used to, if you were using Unix. Add to that, a windowing layer, you got a Desktop. So far, this is the same way in Windows. (At least it used to be through Windows 98). But there ends the similarity. Fig 1, shows the building blocks of a Linux OS.
[caption id="" align="alignnone" width="499"]
Linux Architecture - Courtesy Paul Cooper (pgc) on Flikr[/caption]
So, when I installed Gnome, I basically added to the desktop layer at the very top. The underlying layers (including Window Manager and X-Windows) were unaffected. This is why, my set-up was unaffected. Wow, truly modular programming! Similarly, I could actually replace a hardware and Linux would simply find appropriate drivers (or you can install it) and everything is working again! I couldn't help compare this to MS-Windows, if I changed hardware (even as simple as moving the hard drive with the OS to a new machine), it will be a nightmare to get it working again. Kudos to Linux community.
I really hope they fix the bug(s) in Unity, so I can get back to it in the future. But, I am not exactly missing anything here. Because, Gnome is actively developed in the community. Further, my desktop is definitely running faster than with Unity. (Another complaint about Unity on the web).
P.S: If you are wondering how I got the screen capture of the logon page, that's another strength of Linux (Again, you couldn't do this in windows). There is a whole slew of things to read up on X-windows. I will post more on this later. For now, refer to the link in the references below.
Now I can proudly say, my PC is
Installing a new Desktop
While researching the issue, I found out that I could replace my desktop interface easily with Gnome desktop I used to like!! This blew my mind!! What? Replacing desktop? You mean re-installing complete OS, right? At least, that's what I am used in the MS-Windows environment. No, not with Linux. Here is a link I used in getting the new desktop installed. This put Gnome right beside Unity. All I had to was switch to Gnome when I logged in (See Fig. 1). So far, it's working fine. Apart from this, my applications and settings are still there. It connected to network and printer right away, so I didn't miss anything. (Note: While logging in I had to use Gnome (No effects), to get the same desktop look I had in 10.x.).
[caption id="attachment_455" align="alignnone" width="274"]
(Note: to get to this list, click on the ubuntu icon
Coming from MS Windows environment, I didn't think this was possible*. Not that I am a Micorsoft basher or anything. I've worked on MS Windows, most of my working career. I believe, MS-Windows is part of the evolution process a lot of us went through in the Software industry. Even so, I couldn't avoid being disappointed with MS-Windows. First of all, there is no such option with MS-Windows. With windows, if you wanted a different desktop, you would have to reinstall different version of OS. Remember Vista? When it came out it was buggy. Microsoft offered that you could "downgrade" to XP one time. But then, you lost the shiny new OS called Vista. On top of that, when I switch to a new OS like that, I am sure to face an issue or 2 to get it to work with the set-up I have. No, this was not supposed to be possible.
(Note *: There were some custom desktops available from 3rd party, but nothing fitted in smoothly, as Gnome did here! Further, they typically ran on top of the existing windows desktop, so they were slower).
Secret lies in Linux Architecture
So, I researched this a bit more. Apparently, Ubuntu (actually any linux and Unix) OS is built in a modular way. One layer can be easily replaced without disturbing another. As you know, underneath it all, there is kernel, the core shell in the OS. Then there is command line interface which is what we were used to, if you were using Unix. Add to that, a windowing layer, you got a Desktop. So far, this is the same way in Windows. (At least it used to be through Windows 98). But there ends the similarity. Fig 1, shows the building blocks of a Linux OS.
[caption id="" align="alignnone" width="499"]
So, when I installed Gnome, I basically added to the desktop layer at the very top. The underlying layers (including Window Manager and X-Windows) were unaffected. This is why, my set-up was unaffected. Wow, truly modular programming! Similarly, I could actually replace a hardware and Linux would simply find appropriate drivers (or you can install it) and everything is working again! I couldn't help compare this to MS-Windows, if I changed hardware (even as simple as moving the hard drive with the OS to a new machine), it will be a nightmare to get it working again. Kudos to Linux community.
I really hope they fix the bug(s) in Unity, so I can get back to it in the future. But, I am not exactly missing anything here. Because, Gnome is actively developed in the community. Further, my desktop is definitely running faster than with Unity. (Another complaint about Unity on the web).
P.S: If you are wondering how I got the screen capture of the logon page, that's another strength of Linux (Again, you couldn't do this in windows). There is a whole slew of things to read up on X-windows. I will post more on this later. For now, refer to the link in the references below.
References
- Gnome Desktop
- Unity Desktop
- Ubuntu
- How to add Gnome Desktop to Ubuntu 12.04
- Another site about installing Gnome Desktop
- How to get screen capture of the Login page
Now I can proudly say, my PC is
Labels:
*nix
,
Desktop
,
desktop interface
,
Gnome
,
gnome desktop
,
Ubuntu
Learning Opportunities online
In Computer Science, we constantly face the challenge of "keeping up" with technology. If you catch up with one, chances your skills are outdated within a few months or years. Part of the problem has been lack of affordable learning opportunities, just to keep up with trends in the field. Of course, there are courses available in Community colleges and local universities, for continuing education. They were challenging in terms of logistics and time. What if you can learn at your own pace and they are affordable and of good quality? Wait no longer!
Did I say affordable? Read Free! Recently I found that a lot of universities are offering free courses online. These are real courses that are offered in classes in those universities, with home works, programming assignments and even exams. The courses are literally free, including study materials online. Some courses even offer some kind of Certificate. They do not offer any course credits though. The universities include reputed institutions like Harvard, MIT, Princeton, Stanford, UC Berkeley. You can read more about this in this NYTimes article.
For more information on the courses offered, check out the links below.
This blogger has listed a few. MIT has a Open Courseware that offers lectures from their courses online.
I am currently taking a course at Coursera and it has about 60,000 students enrolled from all over the world! It's definitely opening up new avenues in bringing technology to those remote areas of the world.Personally, if not anything else, I am using it to keep in touch with the trends in Computer Science. This is also a great opportunity to get your hands on newer technology, if you are stuck with old technologies at work!There is one course coming up at edx,org, offered by UC Berkely, called SAAS - Software as a Service. In this course, one can pick up some cloud programming and hands on experience in Ruby on Rails.
If you are a self learner, there are a lot options throughout the web. Youtube has been a great resource for several topics. Some great minds have put together videos explaining complex topics like Algorithms to mathematics modelling. There is also wikibooks and even a wiki university that have great resources for a self learner. But if you need structure and discipline of a classroom to learn, above sites will help.
So, if you want to brush up on those data structures before the next interview, pick up one of those links and have fun learning!
Did I say affordable? Read Free! Recently I found that a lot of universities are offering free courses online. These are real courses that are offered in classes in those universities, with home works, programming assignments and even exams. The courses are literally free, including study materials online. Some courses even offer some kind of Certificate. They do not offer any course credits though. The universities include reputed institutions like Harvard, MIT, Princeton, Stanford, UC Berkeley. You can read more about this in this NYTimes article.
For more information on the courses offered, check out the links below.
This blogger has listed a few. MIT has a Open Courseware that offers lectures from their courses online.
I am currently taking a course at Coursera and it has about 60,000 students enrolled from all over the world! It's definitely opening up new avenues in bringing technology to those remote areas of the world.Personally, if not anything else, I am using it to keep in touch with the trends in Computer Science. This is also a great opportunity to get your hands on newer technology, if you are stuck with old technologies at work!There is one course coming up at edx,org, offered by UC Berkely, called SAAS - Software as a Service. In this course, one can pick up some cloud programming and hands on experience in Ruby on Rails.
If you are a self learner, there are a lot options throughout the web. Youtube has been a great resource for several topics. Some great minds have put together videos explaining complex topics like Algorithms to mathematics modelling. There is also wikibooks and even a wiki university that have great resources for a self learner. But if you need structure and discipline of a classroom to learn, above sites will help.
So, if you want to brush up on those data structures before the next interview, pick up one of those links and have fun learning!
Sunday, September 2, 2012
To OO or not to OO
I originally wanted to name this post "Object Oriented Concepts - Contd....", but then the Hamletian dilemma came to mind. Every programmer faces this, even today, many years after OO has been widely accepted. Part of the problem is that the OO paradigm requires a change in how we think about a problem.
As we saw earlier, in traditional languages we always think "how to do a task" in a procedural sense. This we could adapt to - after all, we humans are good in giving instructions and making recipes and grocery lists. Programming was a natural extension of this - we told the computer what to do and how to do it. We told the computer what to do while feeding data (nouns) required as parameters to these commands (verbs).
When it comes to OO, we have to start thinking what will be the objects we need and "leave" it to those objects to do the work. Really, it's just repackaging, but it's not easy. We are now forced to think of everything in terms of objects. If it's objects like animals, cars, people etc that are typically used in examples about OO, we can understand. But the moment we try to come up with objects for abstract concepts and purely action oriented tasks, it becomes a daunting task.
Baking a Cake
For e.g., let's look at a simple problem of baking a cake (no disrespect to the chef in the kitchen, but let's abstract it here as simple task here for a minute). A recipe typically talks about how to get, do, heat, bake etc. All verbs. Interspersed will be details about data to be used - how much flour, how much sugar, what temperature, how many minutes etc. These "nouns" are used as parameters to the recipe and off we go. Of course, every now and then people try to "reuse" recipes by switching ingredients.
This simple recipe for a cookie , that highlights these points. It has an instruction with 3 simple steps to make delicious cookies. It has some ingredients (attributes) mentioned - dough, apricot jam, and parameters like temperature at 350 degrees, time for 15 - 18 minutes and 1/3 cup of jam. It is straight forward and it even "reuses" recipe for "basic sugar cookie dough"! We certainly know who is making this cake - you, and the ingredients and implements you will be using.

In our abstraction in a procedural language, we created a program with the instructions to bake a cake. We probably broke down each step into a separate procedure (or function), and created a main function that looked like the recipe and called these functions to get the baking done. We created some variables outside of these functions for the parameters required. This works and even is simple to write. But, we assume a lot of things here, like the main function itself acts like the baker executing the instructions. Controlling the oven may be built in as a built in function, but at some point it has to call something to make it happen.
In OO, the task gets a bit more complicated! First, you would have to start thinking differently. Now, you will have to think about the nouns first. Of course there is cake, the final product. But, there is also the bowl, oven and a fictitious baker - may be you, but object none the less. These other objects were included in our procedural programs, but were not given much importance. Any reusable, replaceable parts of the program will now have to be separate objects. In our example, if we make the Oven and the Baker and bowl objects correctly, they could be reused in making/baking pies as well as switch to make or even pot roast! Guess what, you can even replace the baker easily!! This is what makes OO so reusable and to some "so bloated!".
If you are interested in OO cakes, here is a link on a cake OO.
So, To OO or not to OO?
OO is almost everywhere around us. Language after procedural language (recently PHP, Coldfusion, ABAP, Flash ActionScript) have added OO capabilities in recent years. But then, there are also others that write about the difficulties and shortcomings of OO. The post titled Debate Still Rages Over Object-Oriented Programming discusses such dilemma. While you are there, don't forget to check out Marc Funaro's orginal post here: How OO Almost Destroyed My Business. He has articulated very nicely, why he couldn't and didn't have to switch over to OO completely. And see here for a funny take on Java's OO techniques! Irrespective of such views, OO is here to stay. Even if you don't use OO technology currently, chances are, sooner or later you may be exposed to it.
OO methodologies could get complex and could actually distract a developer from the original goal of getting a working program quickly. General rule of thumb I have, is to use procedural for any small (read quick and dirty - most of my utility programs and scripts fall under this) programs and use OO methodology for any larger (business, corporate, enterprise, framework) programs and programs that have potential to grow in the future. (The truth is, even the quick and dirty program/script could outgrow their originally intended lifetime and objects do creep into those every now and then!). OO definitely enforces certain planning ahead of time, so it takes a bit longer to develop it upfront, but if a program lives long enough, re-usability makes up for the cost over time.
In the cake example above, if I am just making a cake for the family on a weekend, simple procedural implementation would be fine! But, if you are going to be making a cake each weekend or thinking of starting a bakery with several branches down the road, then I better start thinking in OO terms, so we don't have to re-invent a lot of stuff later.
General Design Considerations
As we saw earlier, in traditional languages we always think "how to do a task" in a procedural sense. This we could adapt to - after all, we humans are good in giving instructions and making recipes and grocery lists. Programming was a natural extension of this - we told the computer what to do and how to do it. We told the computer what to do while feeding data (nouns) required as parameters to these commands (verbs).
When it comes to OO, we have to start thinking what will be the objects we need and "leave" it to those objects to do the work. Really, it's just repackaging, but it's not easy. We are now forced to think of everything in terms of objects. If it's objects like animals, cars, people etc that are typically used in examples about OO, we can understand. But the moment we try to come up with objects for abstract concepts and purely action oriented tasks, it becomes a daunting task.
Baking a Cake
For e.g., let's look at a simple problem of baking a cake (no disrespect to the chef in the kitchen, but let's abstract it here as simple task here for a minute). A recipe typically talks about how to get, do, heat, bake etc. All verbs. Interspersed will be details about data to be used - how much flour, how much sugar, what temperature, how many minutes etc. These "nouns" are used as parameters to the recipe and off we go. Of course, every now and then people try to "reuse" recipes by switching ingredients.
This simple recipe for a cookie , that highlights these points. It has an instruction with 3 simple steps to make delicious cookies. It has some ingredients (attributes) mentioned - dough, apricot jam, and parameters like temperature at 350 degrees, time for 15 - 18 minutes and 1/3 cup of jam. It is straight forward and it even "reuses" recipe for "basic sugar cookie dough"! We certainly know who is making this cake - you, and the ingredients and implements you will be using.
In our abstraction in a procedural language, we created a program with the instructions to bake a cake. We probably broke down each step into a separate procedure (or function), and created a main function that looked like the recipe and called these functions to get the baking done. We created some variables outside of these functions for the parameters required. This works and even is simple to write. But, we assume a lot of things here, like the main function itself acts like the baker executing the instructions. Controlling the oven may be built in as a built in function, but at some point it has to call something to make it happen.
In OO, the task gets a bit more complicated! First, you would have to start thinking differently. Now, you will have to think about the nouns first. Of course there is cake, the final product. But, there is also the bowl, oven and a fictitious baker - may be you, but object none the less. These other objects were included in our procedural programs, but were not given much importance. Any reusable, replaceable parts of the program will now have to be separate objects. In our example, if we make the Oven and the Baker and bowl objects correctly, they could be reused in making/baking pies as well as switch to make or even pot roast! Guess what, you can even replace the baker easily!! This is what makes OO so reusable and to some "so bloated!".
If you are interested in OO cakes, here is a link on a cake OO.
So, To OO or not to OO?
OO is almost everywhere around us. Language after procedural language (recently PHP, Coldfusion, ABAP, Flash ActionScript) have added OO capabilities in recent years. But then, there are also others that write about the difficulties and shortcomings of OO. The post titled Debate Still Rages Over Object-Oriented Programming discusses such dilemma. While you are there, don't forget to check out Marc Funaro's orginal post here: How OO Almost Destroyed My Business. He has articulated very nicely, why he couldn't and didn't have to switch over to OO completely. And see here for a funny take on Java's OO techniques! Irrespective of such views, OO is here to stay. Even if you don't use OO technology currently, chances are, sooner or later you may be exposed to it.
OO methodologies could get complex and could actually distract a developer from the original goal of getting a working program quickly. General rule of thumb I have, is to use procedural for any small (read quick and dirty - most of my utility programs and scripts fall under this) programs and use OO methodology for any larger (business, corporate, enterprise, framework) programs and programs that have potential to grow in the future. (The truth is, even the quick and dirty program/script could outgrow their originally intended lifetime and objects do creep into those every now and then!). OO definitely enforces certain planning ahead of time, so it takes a bit longer to develop it upfront, but if a program lives long enough, re-usability makes up for the cost over time.
In the cake example above, if I am just making a cake for the family on a weekend, simple procedural implementation would be fine! But, if you are going to be making a cake each weekend or thinking of starting a bakery with several branches down the road, then I better start thinking in OO terms, so we don't have to re-invent a lot of stuff later.
General Design Considerations
Irrespective of whether we use OOP (OO programming language) or not, we are bound to use the modern techniques like Abstraction, Encapsulation, Inheritance and Polymorphism in our program designs. Underlying all these, is the code reuse, data hiding and of course modular design. These of course are not OO by themselves, but are the foundations of OO techniques. By nature of it, OO is almost automatically modular.
- Keep your code Clean
If the code is not "cleanly" written, even you cannot understand it a year later. By clean, I mean well commented (documented) and following some coding standards and best practices.
As for coding standards, what's good for one language isn't always good for another - for e.g, in Java we follow Camel case for naming variables while in PB identifiers are mostly in lower case. So, if your system includes programs in different languages, make sure to include language specific standards as well. Also, best practices for any language may change over version. For e.g., there may be newer constructs and/or functions may be available in a later version that are more efficient than what was available earlier. Make sure to keep up with those in your programs.
OO Note: OOP languages such as Java promote commenting and documenting of the programs easier, with the Javadoc tool (even more so, with IDEs like Eclipse and Netbeans). A well written framework for Java, actually enforces some coding practices automatically. But we can achieve such coding practice with libraries of well written API. A well commented header file distributed along, could act as the documentation for the API.
- Keep it modular
By breaking down your program into smaller modules, your program becomes more manageable. If your program includes specific modules for various functionalities, it will be easier to replace or rewrite or even add a specific module without affecting the entire program. For e.g., if you isolate all database related functions to a separate module, then if your database changes, then all you have to do is to replace this one module. In our cake example above, we could simply add an object for Microwave and start using it instead of Oven, if oven breaks down!
OO Note: Writing such "modular" programs comes naturally in OO languages as the program is essentially built around objects (or classes). But this concept itself is not new. For e.g., in C, you can achieve this by keeping different modules in separate source files), your program becomes more manageable.
- Make the code Reusable
How many times, have you "cut and pasted" your code from one source file to another to "reuse"? If the program is properly designed, then the reuse would be much easier and automatic.
OO Note: In OO, inheritance promotes reuse naturally. A well written framework or class libraries contain reusable classes and methods. Apart from using the classes in the framework themselves, one could extend those via inheritance and thus more custom classes for others in a company to reuse. For e.g., you can create custom loggers specific for your need, by extending classes in log4J library.
But again, this is not specific to OO. In a procedural language like C, one could build libraries of reusable functions. While C doesn't allow extension through inheritance, reuse can be achieved through composition. An inheritance is typically defined by a is-A relationship, while a composition by a has-A. Here is an excellent article that compares the two.
Labels:
Methodologies
,
Object Oriented
,
Programming
Saturday, August 4, 2012
My journey with Ubuntu Contd - On to Precise Pangolin
Linux via Ubuntu
I posted about my first Ubuntu machine earlier. Though I've used Unix for a long time and Linux for a bit for work related activities, this was the first time, I boldly went for Linux at home! Ubuntu made it possible with a great Windows like Desktop.
It was an experimental machine we built with Intel Atom PC (Atom 230 160GHz X2). It worked well with Ubuntu 10.x I installed earlier. In fact, for over a year I managed with10GB hard drive. Sure, it complained about running out of space constantly and I kept moving my files out to Windows PC (Remote Desktop from Ubuntu to Windows worked like a charm). With limited memory and resources, it worked so great, often times better than my newer, more powerful HP machine with Windows Vista.
It has been an amazing journey with Ubuntu. A lot of software I came to know on a Windows PC over the years, are now available on Linux, free and sometimes with better functionality. I installed, Firefox, Google Chrome (it is called Chromium), Libre Office (successor of Open Office, replacement for Microsoft office, I use this a lot on Windows as well) and even my mail client, Mozilla Thunderbird. I could do Remote Desktop to Windows, copy and share files, print to a HP printer almost automatically (on a Windows PC, each time I have to install drivers, here Linux almost finds its own). And of course, internet works right out of the box in Linux.
Moving on, Upgrade
Recently, I decided to continue using Linux and it was time to upgrade. It's still running on an Atom mother board, but I added a new 1TB hard drive. This time I wanted to try to different flavors of Linux. So, I tried installing Ubuntu 12.04, Fedora and Debian. Debian interface was not that great, but seems more powerful. Wiki page on Debian mentions about 3000 volunteer developers developing it over a time period (since 1993). Definitely a matured operating system. But, it's also overwhelming for a first time user.
Fedora 17 is looking nice too. It's community project sponsored by Red Hat. In version 17, it's installation is as easy as Ubuntu and desktop was as flashy too. I tried all 3. I first installed all the 3. But, some how I was drawn back to Ubuntu. Nothing against the other 2, except Ubuntu as ever was easier and better for Ubuntu beginners.
I've also looked at Open Suse and Oracle Linux. So far, I haven't tried them out yet.
Partitioning
Each Linux Dist. comes up with their own Partition Editor which was easy to use. Ubunbtu has GParted, a Partition Editor which is really user-friendly. I remember using Fdisk on DOS systems earlier. You have to exercise, so much caution, otherwise you could lose all partitions. GParted lets you "play" with partitions and it doesn't save anything until you confirm it. When you partition the drive using GParted, you specify which drive belongs to what location (File System and Mount Points). Ubuntu assigns File System names automatically and you can assign a mount point (like /, /home, /boot etc) to each partition. I researched on the Internet and came up with a simple partitioning scheme (I gave 300GM to Ubuntu):
Recommended Partitioning Scheme for a simple Ubuntu installation
This was good, until I installed too many software and root "/" was running out of space. I booted with the Ubuntu Install CD and adjusted the partitions. It was so easy, as I had a lot of empty space to widen the partitions. (Getting to the partition Editor on installer CD was a bit tricky. I had to make the PC boot sequence to CD first. Then when CD booted, I had to pick "Try Ubuntu". Gparted is part of the installation disk).
Multiple Operating Systems
Since I got a bigger disk, I decided to go with all the 3.I tried Ubuntu, Fedora and Debian, side by side. I also tried Partition editor with multiple OS installed. Each OS will see the other OSs partitions in Partition Editor. I learned about sharing the Home directory with multiple OS and changed the mount point for /home to point to the same partition in each OS. Make sure to un-check the "Format" Checkbox, otherwise new install will overwrite any earlier home directory.
One problem I had, having all 3 OS installed was a problem with Grub (Linux Boot Loader). Some how, it was hanging in one of the OSs. (I mixed 64-bit OS for Fedora and Debian, so it was not a fair comparison. Later I tried 64-bit Ubuntu, it crashed too! Intel Atom 230 is claimed to be 64-bit compatible, but 64-bit OS didn't perform well. Probably has to do with memory limitation too. I only have 2GB).
Ubuntu, again!
Having issues with multiple OS installations, I decided to go with one main OS. After reading a bit about comparisons on-line, I decided to go with the known devil (sorry to call it that), Ubuntu. But Ubuntu itself has changed much. Version 10.x was a great OS. The new version, Ubuntu 12.04 LTS is code-named Precise Pangolin ( Apparently Ubuntu 10.x was called Lucid Lynx). LTS means Long Term Support series (love the way they come up with these names!!), they already have plans for Ubuntu 14.04 through 2019 (See here), that's long-term for you and me!!
Precise Pangolin User Interface
To be honest, I was a bit disappointed with the latest version of Ubuntu initially. It still has a windowing desktop, but they have changed the software behind it. They have switched their Graphic interface to use what's called Unity Interface. Prior versions used Gnome interface. To me Gnome was a bit more user-friendly. I am still getting used to the new launcher bar that shows quick launch icons for applications. Every new Application installed already gets pinned to the launcher bar and you can unlock it.
[caption id="attachment_423" align="aligncenter" width="300"]
Ubuntu 12.04 Pangolin Desktop[/caption]
The problem is the launcher bar also includes those that are running. Only thing that shows it is running is the small triangle on either side of the icons. (For e.g, see image on the left. The white triangle on the left shows that the settings->Appearance is running.
[caption id="" align="aligncenter" width="115"]
An icon on the Launch Bar; Triangle on the left indicates running[/caption]

Sort of going back in time, it seems. (Windows 7 changed their task bar too. It works something similar to launch bar here. Why do they keep changing something we are used to??).
Apparently, I am not the only one that's not happy with Unity Interface. This link goes one step further and talks about how to install and get back Gnome desktop on Pangolin.
Copy the old files
I wanted to copy the files I had on the old Linux drive. After a bit of fumbling, I put the old drive inside an external hard drive enclosure and connected to the machine as a USB drive. This worked like magic. The hard drive showed up as a mounted volume. All I had to do was copy the home directory.
[caption id="attachment_411" align="aligncenter" width="535"]
External Volumes are mounted and show up in Devices List[/caption]
Unfortunately, I had encrypted my home directory when I installed Ubuntu last time. So I tried the other way around. I went into BIOS menu (pressing F2 at boot time, on some computers you may have to use DEL key) and changed the boot sequence to boot from USB drive, saved and rebooted. It was a bit slow, but surely it booted from the external drive with the old version (v 10.x) of Ubuntu. And as usual, the new hard drive showed up as a mounted volume too. Then it was just a matter of copying the files over to my new home!!! On windows, some of these tasks could have turned into nightmare. It's so refreshing to use a OS that has less issues for a beginner.
Go Virtual
Then, I discovered about Virtual box. I un-installed all 3, wiped the disk and reinstalled Ubuntu and this I gave it full 600GB. My goal is to install Virtual Box and install multiple Guest OSs.While researching this, I found out about appliances! You can actually build minimal OS distributions with specific applications (like Web Server). Take a look at the Suse Linux page for creating such appliances.I also tried Oracle Developer Day Database appliance. With this I could try out Oracle 11g (we are still at Oracle 10g at work) finally.
[caption id="attachment_412" align="aligncenter" width="300"]
Virtual Box Application main Screen[/caption]
I will post about Virtualization separately.
I posted about my first Ubuntu machine earlier. Though I've used Unix for a long time and Linux for a bit for work related activities, this was the first time, I boldly went for Linux at home! Ubuntu made it possible with a great Windows like Desktop.
It was an experimental machine we built with Intel Atom PC (Atom 230 160GHz X2). It worked well with Ubuntu 10.x I installed earlier. In fact, for over a year I managed with10GB hard drive. Sure, it complained about running out of space constantly and I kept moving my files out to Windows PC (Remote Desktop from Ubuntu to Windows worked like a charm). With limited memory and resources, it worked so great, often times better than my newer, more powerful HP machine with Windows Vista.
It has been an amazing journey with Ubuntu. A lot of software I came to know on a Windows PC over the years, are now available on Linux, free and sometimes with better functionality. I installed, Firefox, Google Chrome (it is called Chromium), Libre Office (successor of Open Office, replacement for Microsoft office, I use this a lot on Windows as well) and even my mail client, Mozilla Thunderbird. I could do Remote Desktop to Windows, copy and share files, print to a HP printer almost automatically (on a Windows PC, each time I have to install drivers, here Linux almost finds its own). And of course, internet works right out of the box in Linux.
Moving on, Upgrade
Recently, I decided to continue using Linux and it was time to upgrade. It's still running on an Atom mother board, but I added a new 1TB hard drive. This time I wanted to try to different flavors of Linux. So, I tried installing Ubuntu 12.04, Fedora and Debian. Debian interface was not that great, but seems more powerful. Wiki page on Debian mentions about 3000 volunteer developers developing it over a time period (since 1993). Definitely a matured operating system. But, it's also overwhelming for a first time user.
Fedora 17 is looking nice too. It's community project sponsored by Red Hat. In version 17, it's installation is as easy as Ubuntu and desktop was as flashy too. I tried all 3. I first installed all the 3. But, some how I was drawn back to Ubuntu. Nothing against the other 2, except Ubuntu as ever was easier and better for Ubuntu beginners.
I've also looked at Open Suse and Oracle Linux. So far, I haven't tried them out yet.
Partitioning
Each Linux Dist. comes up with their own Partition Editor which was easy to use. Ubunbtu has GParted, a Partition Editor which is really user-friendly. I remember using Fdisk on DOS systems earlier. You have to exercise, so much caution, otherwise you could lose all partitions. GParted lets you "play" with partitions and it doesn't save anything until you confirm it. When you partition the drive using GParted, you specify which drive belongs to what location (File System and Mount Points). Ubuntu assigns File System names automatically and you can assign a mount point (like /, /home, /boot etc) to each partition. I researched on the Internet and came up with a simple partitioning scheme (I gave 300GM to Ubuntu):
Recommended Partitioning Scheme for a simple Ubuntu installation
Partition | Location | Size | Comments |
---|---|---|---|
Partition 1 | /boot | 10GB | |
Partition 2 | / | 50GB | |
Swap File | 5GM | Twice the size of memory | |
Partition 3 | /home | 235GM |
This was good, until I installed too many software and root "/" was running out of space. I booted with the Ubuntu Install CD and adjusted the partitions. It was so easy, as I had a lot of empty space to widen the partitions. (Getting to the partition Editor on installer CD was a bit tricky. I had to make the PC boot sequence to CD first. Then when CD booted, I had to pick "Try Ubuntu". Gparted is part of the installation disk).
Multiple Operating Systems
Since I got a bigger disk, I decided to go with all the 3.I tried Ubuntu, Fedora and Debian, side by side. I also tried Partition editor with multiple OS installed. Each OS will see the other OSs partitions in Partition Editor. I learned about sharing the Home directory with multiple OS and changed the mount point for /home to point to the same partition in each OS. Make sure to un-check the "Format" Checkbox, otherwise new install will overwrite any earlier home directory.
One problem I had, having all 3 OS installed was a problem with Grub (Linux Boot Loader). Some how, it was hanging in one of the OSs. (I mixed 64-bit OS for Fedora and Debian, so it was not a fair comparison. Later I tried 64-bit Ubuntu, it crashed too! Intel Atom 230 is claimed to be 64-bit compatible, but 64-bit OS didn't perform well. Probably has to do with memory limitation too. I only have 2GB).
Ubuntu, again!
Having issues with multiple OS installations, I decided to go with one main OS. After reading a bit about comparisons on-line, I decided to go with the known devil (sorry to call it that), Ubuntu. But Ubuntu itself has changed much. Version 10.x was a great OS. The new version, Ubuntu 12.04 LTS is code-named Precise Pangolin ( Apparently Ubuntu 10.x was called Lucid Lynx). LTS means Long Term Support series (love the way they come up with these names!!), they already have plans for Ubuntu 14.04 through 2019 (See here), that's long-term for you and me!!
Precise Pangolin User Interface
To be honest, I was a bit disappointed with the latest version of Ubuntu initially. It still has a windowing desktop, but they have changed the software behind it. They have switched their Graphic interface to use what's called Unity Interface. Prior versions used Gnome interface. To me Gnome was a bit more user-friendly. I am still getting used to the new launcher bar that shows quick launch icons for applications. Every new Application installed already gets pinned to the launcher bar and you can unlock it.
[caption id="attachment_423" align="aligncenter" width="300"]
The problem is the launcher bar also includes those that are running. Only thing that shows it is running is the small triangle on either side of the icons. (For e.g, see image on the left. The white triangle on the left shows that the settings->Appearance is running.
[caption id="" align="aligncenter" width="115"]
Apart from these, how you get to things is also different. The Gnome toolbar that had "Applications", "Places" etc disappeared. To get to the applications, you either go through Launch bar and if you don't have it there (Launch bar is menu of icons, so size is limited), then you go to Dash Home by clicking on the icon on the Launch bar and then type the application you need. For e.g., to get Kompozer (HTML editor that's not in my Launch Bar, I have to pull up Dashboard and type some chars to get to the application.
Sort of going back in time, it seems. (Windows 7 changed their task bar too. It works something similar to launch bar here. Why do they keep changing something we are used to??).
Apparently, I am not the only one that's not happy with Unity Interface. This link goes one step further and talks about how to install and get back Gnome desktop on Pangolin.
Copy the old files
I wanted to copy the files I had on the old Linux drive. After a bit of fumbling, I put the old drive inside an external hard drive enclosure and connected to the machine as a USB drive. This worked like magic. The hard drive showed up as a mounted volume. All I had to do was copy the home directory.
[caption id="attachment_411" align="aligncenter" width="535"]
Unfortunately, I had encrypted my home directory when I installed Ubuntu last time. So I tried the other way around. I went into BIOS menu (pressing F2 at boot time, on some computers you may have to use DEL key) and changed the boot sequence to boot from USB drive, saved and rebooted. It was a bit slow, but surely it booted from the external drive with the old version (v 10.x) of Ubuntu. And as usual, the new hard drive showed up as a mounted volume too. Then it was just a matter of copying the files over to my new home!!! On windows, some of these tasks could have turned into nightmare. It's so refreshing to use a OS that has less issues for a beginner.
Go Virtual
Then, I discovered about Virtual box. I un-installed all 3, wiped the disk and reinstalled Ubuntu and this I gave it full 600GB. My goal is to install Virtual Box and install multiple Guest OSs.While researching this, I found out about appliances! You can actually build minimal OS distributions with specific applications (like Web Server). Take a look at the Suse Linux page for creating such appliances.I also tried Oracle Developer Day Database appliance. With this I could try out Oracle 11g (we are still at Oracle 10g at work) finally.
[caption id="attachment_412" align="aligncenter" width="300"]
I will post about Virtualization separately.
Monday, April 16, 2012
Object Oriented Concepts - An Introduction
Work has been busy for a while. I am finally returning to my blog on PB.
We started looking at PB program as a collection of Objects in the last post. Yes, PB is now an object oriented language, but it sure did not start that way. Sure it has some objects like windows, buttons etc, but does that make it an Object oriented environment automatically? This topic itself is so huge, So, I decided to touch on these first before continuing further with PB.
What is an Object?
The simplest definition of an object is a thing, a noun or an entity. In the programming world, this has come to mean a self contained programming unit. By hooking different "objects" you can make a program. Objects themselves are not new. Remember the old C programs? When you compile individual C files in a program, they were converted to "object" file. Though it doesn't mean the same, it stands for a program unit. By linking different "object" files, we arrived at the final program (Executable). Then there were modules. Even though there is a subtle difference between a module and an object, in theory they are the building blocks of a program. Remember, COM (Microsoft .Net evolved out of this eventually)? The idea was to have bunch of OLE (eventually called Active-X) that would be glued together in a program. In fact, Visual Basic was invented for such a purpose originally. We will explore more about objects in the coming posts. But, while you are at it, think about another term frequently used in OO: a Class. Several authors allude this to a blueprint, cookie cutter, a mold for creating objects.
What is Object Orientation (OO)?
An object has several other characteristics that makes an object in an Object-oriented language different from earlier definitions of objects. If you Google for the word “Object oriented”, you will find a million links. If you sift through all those, you will come to the following conclusion:
Object Oriented is a new paradigm (though it's been around for 30+ years now) and it is difficult to learn and/or master. Yet you see, every programming language (PHP, Coldfusion, PERL, PYTHON, you name it) out there is joining the OO way. So, if you are going this route, you have to get the concepts right.
Object oriented is many different things to many different people. Even the languages that claim to support OO now, are not fully OO themselves. So, let us discuss fundamental definition of being object oriented. In later posts, we will continue to drill down this topic.
Several books talk about Object Oriented (OO) approach to contain the following four basic characteristics
We will analyze each of these below.
Abstraction
Almost anything we do with computer software is an abstraction of the real world. An ATM machine is essentially modeled after a real-life teller it came to replace. Abstraction itself is not OO. Cobol and Fortran programs abstracted business models and mathematical models respectively for about 50 years now. But the abstraction in OO, is much closer to the real life. After all, real life is full of objects: people, earth, machines, food, microwaves, books, TV, radio etc.
In OO, we try to call a Radio a radio and define it's properties and operations to emulate real life one (actually a radioObject is more appropriate name for it; of course, it's a software object not a real one, but you could make it to play music!). A software abstraction is context based. For e.g., when we abstract customers, shop owners and employers we are abstracting people. In such an abstraction, we definitely would like to know their names, but we don't need know their race, gender, height, weight etc. Where as, if the person abstracted is a patient, suddenly some of these characteristics matter!
A speedometer in a car is a good example for abstraction. We see the needle to get an idea as to how “fast” or slow the car is going. Abstraction in this case varies between MPH in the US to Kilometers in some other countries. A thermometer, similarly abstracts how "hot" outside temperature is.
Encapsulation
This is the next characteristic of an OO programming environment. Encapsulation, simply means hiding private data and showing proper (public) interface. We don't want to see inner-workings of a microwave or a car when we are using it to heat our pizza or driving to get one. When we shop for a car, we are happy if we find a steering wheel, something that looks like gear, brakes and of course, those 4 wheels that the car needs to “run”. Of course, some of us would like little more glossy finish, but none of these involve putting engines right next to you on the front seat! And of course, the way those engines come pretty well sealed these days, they are very well encapsulated themselves. There is one “interface” you see, the oil cap that lets you fill oil. The content, level of oil, is not immediately visible. If you open and use a dip stick, you can find out the actual level of oil!
Speedometer mentioned above is also a good example of encapsulation. To “see” speed one doesn't need to look at rotating gears, tires, road etc. They just look at the interface called “Speedometer”.
Encapsulation itself is not a new concept. It's been around since the early days of programming. In Pascal, you could achieve certain amount of encapsulation by proper function design. C of course, offered modular programming (file level – see post “Modular progamming in C” for more information).
Inheritance
The most common meaning for this English word is the property (read “Wealth”) inherited from ancestors when they pass on. And it's not just property that can be inherited. We also talk about some characteristics passed on (genetically). It's this latter mean that's adapted in the computer lingo. Inheritance in OO allows an object to acquire properties and behavior of some other. So, we talk of a Dog object inheriting properties of an animal object (actually class, we will discuss these shortly).
Of course, in real life we don't say Dog inherited from Animal. We say, Dog “Is A” animal. We also say Car “has a” engine. And we have access (reference) to computers in the hotel. These are different types of object relationships in OO. An “Is A” is considered to be inheritance. A “Has A” relationship is called composition. And a reference to an object out there, is an Association.
Of these, Composition and Association were possible is non-OO languages as well. Inheritance itself could be indirectly implemented through these 2. For e.g., in C, using plain structures and function pointers we could mimic any of the above relationships.
Polymorphism
This came from a Greek word. Poly means many, morph – form. For e.g., different forms of shapes. Circle, Square, Rectangle and Triangle are all shapes. Of these, Rectangle and Square are similar, in that they both have sides. Circles and Ovals could be similar.
Now, shape is a noun, an object. How about a verb – an action or behavior? Let's take the word “Play”. Try using this English word in sentences and you will see how many different objects can play in how many different ways. Like playing a piano, like playing Football, Playing cards, playing a part in a play, Play with a child, Playing with life! This is truly a polymorphic word. How about the word, “Talk”? “Talk” to a dog, barks, cat meows and the cow moos, not exactly talk in the human sense, but in the sense of “open your mouth and make a sound” it's the same operation, with various forms!
In this post, we tried to explain what OO is and try to understand the terminologies typically related to the OO. This wasn't totally a technical discussion. Now that we got some definitions out of the way, let's get down to business with the topic of Object Oriented. Try to remember some of the examples when we get to our next post.
Below picture summarizes all these terminology as they relate to a Microwave.

We started looking at PB program as a collection of Objects in the last post. Yes, PB is now an object oriented language, but it sure did not start that way. Sure it has some objects like windows, buttons etc, but does that make it an Object oriented environment automatically? This topic itself is so huge, So, I decided to touch on these first before continuing further with PB.
What is an Object?
The simplest definition of an object is a thing, a noun or an entity. In the programming world, this has come to mean a self contained programming unit. By hooking different "objects" you can make a program. Objects themselves are not new. Remember the old C programs? When you compile individual C files in a program, they were converted to "object" file. Though it doesn't mean the same, it stands for a program unit. By linking different "object" files, we arrived at the final program (Executable). Then there were modules. Even though there is a subtle difference between a module and an object, in theory they are the building blocks of a program. Remember, COM (Microsoft .Net evolved out of this eventually)? The idea was to have bunch of OLE (eventually called Active-X) that would be glued together in a program. In fact, Visual Basic was invented for such a purpose originally. We will explore more about objects in the coming posts. But, while you are at it, think about another term frequently used in OO: a Class. Several authors allude this to a blueprint, cookie cutter, a mold for creating objects.
What is Object Orientation (OO)?
An object has several other characteristics that makes an object in an Object-oriented language different from earlier definitions of objects. If you Google for the word “Object oriented”, you will find a million links. If you sift through all those, you will come to the following conclusion:
Object Oriented is a new paradigm (though it's been around for 30+ years now) and it is difficult to learn and/or master. Yet you see, every programming language (PHP, Coldfusion, PERL, PYTHON, you name it) out there is joining the OO way. So, if you are going this route, you have to get the concepts right.
Object oriented is many different things to many different people. Even the languages that claim to support OO now, are not fully OO themselves. So, let us discuss fundamental definition of being object oriented. In later posts, we will continue to drill down this topic.
Several books talk about Object Oriented (OO) approach to contain the following four basic characteristics
- Abstraction
- Encapsulation
- Inheritance
- Polymorphism
We will analyze each of these below.
Abstraction
Almost anything we do with computer software is an abstraction of the real world. An ATM machine is essentially modeled after a real-life teller it came to replace. Abstraction itself is not OO. Cobol and Fortran programs abstracted business models and mathematical models respectively for about 50 years now. But the abstraction in OO, is much closer to the real life. After all, real life is full of objects: people, earth, machines, food, microwaves, books, TV, radio etc.
In OO, we try to call a Radio a radio and define it's properties and operations to emulate real life one (actually a radioObject is more appropriate name for it; of course, it's a software object not a real one, but you could make it to play music!). A software abstraction is context based. For e.g., when we abstract customers, shop owners and employers we are abstracting people. In such an abstraction, we definitely would like to know their names, but we don't need know their race, gender, height, weight etc. Where as, if the person abstracted is a patient, suddenly some of these characteristics matter!
A speedometer in a car is a good example for abstraction. We see the needle to get an idea as to how “fast” or slow the car is going. Abstraction in this case varies between MPH in the US to Kilometers in some other countries. A thermometer, similarly abstracts how "hot" outside temperature is.
Encapsulation
This is the next characteristic of an OO programming environment. Encapsulation, simply means hiding private data and showing proper (public) interface. We don't want to see inner-workings of a microwave or a car when we are using it to heat our pizza or driving to get one. When we shop for a car, we are happy if we find a steering wheel, something that looks like gear, brakes and of course, those 4 wheels that the car needs to “run”. Of course, some of us would like little more glossy finish, but none of these involve putting engines right next to you on the front seat! And of course, the way those engines come pretty well sealed these days, they are very well encapsulated themselves. There is one “interface” you see, the oil cap that lets you fill oil. The content, level of oil, is not immediately visible. If you open and use a dip stick, you can find out the actual level of oil!
Speedometer mentioned above is also a good example of encapsulation. To “see” speed one doesn't need to look at rotating gears, tires, road etc. They just look at the interface called “Speedometer”.
Encapsulation itself is not a new concept. It's been around since the early days of programming. In Pascal, you could achieve certain amount of encapsulation by proper function design. C of course, offered modular programming (file level – see post “Modular progamming in C” for more information).
Inheritance
The most common meaning for this English word is the property (read “Wealth”) inherited from ancestors when they pass on. And it's not just property that can be inherited. We also talk about some characteristics passed on (genetically). It's this latter mean that's adapted in the computer lingo. Inheritance in OO allows an object to acquire properties and behavior of some other. So, we talk of a Dog object inheriting properties of an animal object (actually class, we will discuss these shortly).
Of course, in real life we don't say Dog inherited from Animal. We say, Dog “Is A” animal. We also say Car “has a” engine. And we have access (reference) to computers in the hotel. These are different types of object relationships in OO. An “Is A” is considered to be inheritance. A “Has A” relationship is called composition. And a reference to an object out there, is an Association.
Of these, Composition and Association were possible is non-OO languages as well. Inheritance itself could be indirectly implemented through these 2. For e.g., in C, using plain structures and function pointers we could mimic any of the above relationships.
Polymorphism
This came from a Greek word. Poly means many, morph – form. For e.g., different forms of shapes. Circle, Square, Rectangle and Triangle are all shapes. Of these, Rectangle and Square are similar, in that they both have sides. Circles and Ovals could be similar.
Now, shape is a noun, an object. How about a verb – an action or behavior? Let's take the word “Play”. Try using this English word in sentences and you will see how many different objects can play in how many different ways. Like playing a piano, like playing Football, Playing cards, playing a part in a play, Play with a child, Playing with life! This is truly a polymorphic word. How about the word, “Talk”? “Talk” to a dog, barks, cat meows and the cow moos, not exactly talk in the human sense, but in the sense of “open your mouth and make a sound” it's the same operation, with various forms!
In this post, we tried to explain what OO is and try to understand the terminologies typically related to the OO. This wasn't totally a technical discussion. Now that we got some definitions out of the way, let's get down to business with the topic of Object Oriented. Try to remember some of the examples when we get to our next post.
Below picture summarizes all these terminology as they relate to a Microwave.
Labels:
Introduction to Powerbuilder
,
OO
,
software-development
Subscribe to:
Posts
(
Atom
)