Importing Inherited Implements

What’s the difference between Imports, Inherits and Implements?

Imports
…lets the developer USE a Namespace, using a referenced library; eg. the Math Object is under the System Namespace, so in order to use the functions that it shares, you’ll declare “Imports System.Math” somewhere in your code.You can use any library that you have referenced in your project WITHOUT using Imports keyword by typing the full class path, eg. “a = System.Math.Abs(10.2);”. By using the Imports keyword, however, you can shorten the line of code to just “a = Abs(10.2);”.

Implements
…lets the developer EXTEND a Class, using an Interface. These interfaces usually start with the capital I in front of them, and implementing one of these would force a class to use certain names and types of certain methods and properties. You have to explicitly declare these constraints, or the class will not compile. However: the Interface itself cannot contain any code, it just enforces a pattern so that other objects can call a generic interface to address multiple implementations.

Inherits
…also lets the developer EXTEND a Class, but this time using a base class. The base class are complete classes with working methods and properties. It does not enforce any constraints to the class that’s inheriting it (unlike Interfaces) so you can overload (or choose to ignore) any method you like.

~~~

An Analogy: Everyone can become Wet. Dogs are Animals. Cats are Animals. All Carnivores can eat Meat.

Now, since everyone can access the method MakeWet, then an “Imports System.Water” might have been declared, so that everyone can just call the Method “MakeWet” instead of repeatedly writing “System.Water.MakeWet”.

We can say that both Dogs and Cats implement the interface IAnimal. This way, we can give both of them the method IAnimal.Talk() and force the coder to write code inside the function. Afterwards, since all animals have the same method name ‘Talk()’, we can use them like so:
Zoo.Add(New Dog)
Zoo.Add(New Cat)
For Each Animal as IAnimal in Zoo
Animal.Talk()
End For
// Output:
// ”Woof Woof”
// ”Meow Meow”
However, all animals eat alike. Instead of copy-pasting the eat method on each animal, lets just have them inherit the Base Class clsCarnivore, which automatically gives them the method ‘EatMeat’. Of course, if an animal only eats certain kinds of meat, we can overload the method, but if not, no extra code is needed.

There, and done~! Don’t get confused.. Until next post, Sayonara~

w00+! Btw, what's the opposite of writer's block?

Ok, so I said quite a few posts back that I'm pulling back on blog posts to focus on my new job at Isuzu Automotive. However, I'm quite inspired these past few days (maybe because of the thrill of educating again), and I'm currently writing 3 blog posts for you guys ^^ Yey!

Now, I'm about finished with the first one: Inherits Implements and Imports, so that'll go up approximately tomorrow evening. One of my superiors asked me about the difference between them, and I couldn't remember off the top of my head. So I decided to do some research and write about it here.

Next is a fun post, which will also be the first post on my new (!!) blog: FinalFantasy14.Philippines. I got a Beta Key for the Square-Enix's upcoming MMORPG: Final Fantasy 14, and I'll try to document what I learn and share the experience in a filipino player's perspective.

Lastly, I'm writing something about developing Android Applications. I brought an HTC Wildfire last week, and I'm kindof intrigued with the development of Android as an operating system.

Ok, that's it! I need to go write some more~ Sayonara, for now!

Trippy Dot Net

Slide Notes Here: http://ow.ly/2qFmJ


2nd seminar in a month c-c-combo! I'm getting my old confidence back :D I'll try to schedule another one next next tuesday (which I will post here too) about Unit Testing~ But in the meantime, here's a few choice bits about my take on Exception Handling (Part 1 of my 3P.Net series):

Be wary of using Try..Catch Exception Handling! Its tempting to use the infamous "Try All, Catch Everything" mentality throughout your code, but that will cause a lot of trouble to you (and your team) in the future. How? Well, aside from a slight performance hit for every line in the try..catch (less than 1ms), by catching exceptions in the lower layers, you're depriving the upper layers from effectively resolving those errors!

An example: If the end user somehow bypasses the validation, and enter a null entry into a non-nullable field, the business logic layer would pass the wrong data to the service layer, who would then try to insert/update the data source. The data source would then issue an exception to the service layer (NullArgumentException). If you resolve the error at the service layer (Log the error then throw a message saying that there's something wrong) then the business logic layer will no longer catch the exception. However! If you let it 'bubble up' (eg. Don't try..catch it, or throw it again after catching it) to the business logic layer, you can now catch all NullArgumentExceptions, fill the null data with a default value, then resend it to the data source. The end user would'nt even know that an exception had happened.

Another thing, it's good practice to throw unresolved exceptions up towards the highest layer, which is commonly the Windows Forms layer (or ASP.Net/WPF/Silverlight layer, whichever the case). The top most layer however, should have a blanket try catch on its containers (form/page/usercontrol, whichever the case) in order to catch any stray unresolved errors that manage to bubble up to the very top. These unresolved errors, are the ones that we have to track with a Bug Tracker.

You can read more about this topics on my slides above, or you could just message me in my Google Profile, Facebook or Twitter. Until next time, sayonara~

Social Networking and Education

Slide Notes Here: http://ow.ly/2mmFT



It has been quite some time since I stood in front of a classroom filled with students. A week ago, Mam (Mich) Ramirez invited me to talk at Lyceum, and I immediately agreed- As you guys know, I like being an educator. But as I stood in front of the students, I suddenly felt fear and my heart started pounding fast.. I guess 'hindi na ko sanay' and I need to start performing talks more. I hope more opportunities like these present themselves..

Anyhow.

My talk was about how college education is not enough, how we must supplement it with knowledge available to us (free!) in the internet, and how to find these knowledge through the use of Social Networking. After that, I talked a bit about blogging (which, ironically, I'm blogging about right now) and which blogging platforms I think is the best. I'll reiterate a bit here:

1) I love Blogger. Absolutely free, No strings attached, moderately customizable and best of all: Allows Ads.
2) Wordpress: for Design Experts.  It requires a small yearly fee, but you can customize a lot of it afterwards: plugins, widgets, themes, etc. Also, a photoshop pro's dream photo blog.
3) Quick & Easy blogging at Tumblr & Posterous. These are free services, little customization (compared to Blogger and Wordpress, at least) but very clean and simple to use.
4) Make your own. You can set up a Joomla, Drupal or a Ruby on Rails web server at home or on a host, get a domain name to get a 100% fully customizable website that can breath fire (if you're a good enough programmer), but of course, you'd need to invest a lot of time, effort and cash to do so. I suggest trying out the free services first.

That's it for today~! If you guys have any questions (about the seminar, blogging or even programming) you can leave a message on my Google Profiles page, or just contact me through Facebook or Twitter. Until next time, Sayonara! *watches the latest Hitman Reborn*

Faith & Prosperity

What a week. First, I attended my job's care group last Thursday (10729) and the topic was about prosperity. Then. my boss gave me and one of my coworkers a ticket to a financial seminar about debt, investment and setting up a business. The seminar was today, and it went well- all three of the speakers were both emotionally moving and very knowledgeable in their topics. After the seminar, I attended the Saturday mass with another coworker, and the homily was about, take a guess: wealth. See the pattern yet?
"Owe no one anything, except to love one another..." ~ Romans 13:8
Dr. Dan Lachica's talk about debt was very inspiring, and although I'm not in debt (except maybe from my parents) I still learned a lot from it. However, what really striked me was his short segue into how cheating somehow affects what happens to you in the future. Dr. Lachica's example was that, if he holds a scalding hot bottle of water, his hand will blister right away- therefore, he immidiately knows that the cause of the blisters is the hot bottle of water. However, if he holds the hot bottle now, and gets blisters after a few days, it would be harder to connect those two events.

Now, let me tell you what happened to me just last week. Yes, a week before my whole week of faith and prosperity-talk with practically everyone.

A week ago, Saturday, I was at the office working as usual with very little care about cash except saving enough for a copy of Final Fantasy 14 come late September. One of my friends asked me if I have time after work, since a new movie that looked interesting was in the theaters (No, not Eclipse, but Sorcerer's Apprentice w/ Nicolas Cage). Since I didn't have anything planned except my weekly Saturday mass at the nearby mall, I agreed. Turns out that the same mall had a screening of the movie we want, 30 mins. right after the mass (coincidence? I didn't think so then, but...)

I met with my friend after work, and we went to the mass together. Before the mass ended, the collection basket was passed for those who'd like to share their blessings with the church- I usually pass it on because... well, I don't really have an excuse. But until then, I don't remember ever putting any of my own money into the collection basket. However, my friend took out his wallet and drew some coins when the basket neared. Feeling a bit guilty, I also looked at my wallet and got some coins out- about six or seven pesos, I'm not sure. We dropped the coins into the basket and the mass continued.

We ate at a fast food, watched the movie (it was good, btw) then went home- a bus then a jeep. Here's when I first noticed something: I had the exact amount of coins left for my ride home, and since I don't like breaking my bills to coins, I decided not to stop at a convenience store for a quick bite.

The next work day, the same thing happened at my workplace's canteen- exact change. Nothing extra to spend on luxuries that I want, but don't need. The week trudged on, and the same things kept happening, up until the weekend came- which I normally spend some extra cash (I had quite a lot, to my surprise). I had quite a fun and I enjoyed hanging out with my friends, until I noticed that I left my jacket at a coffee shop (Town Center's Coffee Bean). It was a favorite of mine, and quite new too- I immediately sms'd my mom about it just in case I never get it back, since me and my friends are already a bit far from where I left it. An hour passed by, almost two hours, before we got back. Lo and behold, I got my jacket back. The shopkeeper's staff kept it for me, and I was really grateful that they did so.

It was an amazing string of "coincidences": starting with a guilty offering of only a few pesos, into saving some cash, into finding my lost jacket, and finally capped with a series of seminars that explained everything. It took me a while before I saw which caused what effect, but I'm sure- 100% sure, that my whole week was planned by Him. I really am blessed, and I'm writing this as way to spread these blessings, to inspire, or at least convince you, that the Lord, our God, is really a generous God.

I don't really like quoting from the bible (it almost always feels like its out of context somehow), but since I started with one, I'll end with another. Until next time, Sayonara!
"As long as the earth endures, seedtime and harvest, cold and heat, summer and winter, day and night will never cease." ~ Genesis 8:22

“Are we really going to use these theories/principles at work?”

While teaching in Letran, or even while studying there a few years back, one question almost always pops up when a professor wraps up a difficult topic: “How do we apply this in the real world?” I have asked this question myself a few times, and now that I'm working in the industry again, I have this rare chance of showing you exactly how the theories are actually used in real applications. I will tag these series here as 'Theory + Reality', and the posts would be about how we can apply the theories we have learned to the software that we would create.

Reality:10716 ~ Blog 1 
Click the Pic to Enlarge!

One of the most common task that we're going to do at the industry is to maintain and improve upon existing software. Look at the code above. This is a small piece of code from the Business Logic (BL) Layer that basically shows some collection of information about the customer. According to my previous blog post about the N-Tier Architecture, the Second Tier is basically a bridge/police between the User Interface and the Data Store, transferring while verifying the data through a set of business rules/policies. Now, let' analyze the code line-by-line.

Line 174: The Business Logic code asked for a ComboBox as a parameter. The alarms in your head should already start ringing- there's something not quite right here. A Combo Box is something the user interacts with, and the bridge/police shouldn't have anything to do with it. Theoretically, what we need is the data- what's inside the ComboBox.
Line 175: It's normally unnecessary to put an entire function in a Try-Catch block. We should only catch errors that we can fix- errors that the business logic layer, or the layers below it, actually creates. Everything else should just bubble up to whoever can resolve the error. Of course, sometimes you need to do this when debugging the code, just to be sure.
Line 176 to 184: This is simply an initialization phase for the parameters that would be used by the next process. Trivia: It's almost impossible to have a runtime error here that the Business Logic layer can resolve.
Line 185: This is the connection to the Data Store. We should hold on to the data that this returns until the User Interface needs it.
Line 186: Here, we use an external object (service as clsService) to bind another external object (the ComboBox), passing the data that we got from the Data Store, which is readily available since the scope of the Set_Get_Lookup property is Public. Obviously, this doesn't belong here. It has nothing to do with any Business Logic, and has everything to do with the User Interface. Take note that one of the features of the BL layer is that we should be able to interchange different UIs easily (this design pattern is known as loose coupling) and by binding the combobox here, we are tightly coupling this part of the code to the current interface.
Line 187: Catch ex as Exception means you would catch ALL exceptions. I will say this again: It's good programming practice to just specify which errors you catch, then let everything else bubble up. The user interface usually has this kind of Try-Catch block, to notify the user that you've done everything you could've done, but the error is still there.
Line 188: This is an impossible line of code. Business Logic layers are normally compiled in a library (a DLL) and libraries, by their very nature, are “headless”. They should never have a User Interface, so calling a MessageBox here is a logical error.

Theory + Reality
10716 ~ Blog 2 
Click the Pic to Enlarge!

You can see in the sanitized and Diff'd code above the design patterns and theories which I applied. Specifically:

Single Responsibility Principle. The business logic layer should have one, definite responsibility only: to act as a bridge/police for the data traveling between the UI and the Data Store. Don't let responsibilities bleed into other layers, or even other objects (also: avoid tight coupling).
Load Once, Use Many Principle. You can find my blog post about the Lazy Initialization design pattern here.
• Better Exception Handling.

That's it! The first of the hopefully many posts in this series is complete, and I hope we've both learned a lot from these. Until the next post, sayonara :D

Post@Posterous? Or Not?



I have been reading Michael Scott's novel, The Alchemyst this last few weeks, and it inspired me to write a short story in the same vein- about teens using magic in the modern world. Aside from posting it in my DeviantArt account, I have also decided to post it in a new blog which has far more editing capabilities. Posterous.com has been making waves in the internet world this past few weeks due to their new features, and I decided to give the service a try.

First things first: The signup was mixed bag. On one hand, all you have to do is email your first post to post@posterous.com and you're automagically signed up. On the other, geeks and experienced bloggers usually set the site up before posting- and it took me a couple of seconds to figure out that the sign up form was on the login page, and not the front page. After that's done though, Posterous accepts OpenId which makes logging in a breeze.

After playing with it for a while, I realized that the site is a far, far cry from Wordpress, or even Blogger. While most Blogging platforms have focused on ever-expanding features, Posterous have focused on Simplicity (a bit like google). They sticked with a simple WYSIWYG interface for posting & editing- there's nothing new in post-by-email, and their autopost to social networks is subpar with what Wordpress offers- for example, you can't choose which link shortener you can use. Also, the initial Themes, while very customizable, are limited to about a dozen.

If the only service you need is a place to put your notes, thoughts or stories into, then you can't get any more simpler than what Posterous offers. Signup, then everything's ready to go- post away!

Note: Sorry I can't post more often and more concise. I don't have Internet Access at work (yet) so I don't have the same amount of resources as before~ I'll still try my best though, gambatte! w00t~