Pages

Thursday, August 26, 2010

Class / Object is

Objects are key to understanding object-oriented technology. Look around right now and you'll find many examples of real-world objects: your dog, your desk, your television set, your bicycle.

Real-world objects share two characteristics: They all have state and behavior. Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Bicycles also have state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes). Identifying the state and behavior for real-world objects is a great way to begin thinking in terms of object-oriented programming.

Take a minute right now to observe the real-world objects that are in your immediate area. For each object that you see, ask yourself two questions: "What possible states can this object be in?" and "What possible behavior can this object perform?". Make sure to write down your observations. As you do, you'll notice that real-world objects vary in complexity; your desktop lamp may have only two possible states (on and off) and two possible behaviors (turn on, turn off), but your desktop radio might have additional states (on, off, current volume, current station) and behavior (turn on, turn off, increase volume, decrease volume, seek, scan, and tune). You may also notice that some objects, in turn, will also contain other objects. These real-world observations all translate into the world of object-oriented programming.

A circle with an inner circle filled with items, surrounded by gray wedges representing methods that allow access to the inner circle.

A software object.

Software objects are conceptually similar to real-world objects: they too consist of state and related behavior. An object stores its state in fields (variables in some programming languages) and exposes its behavior through methods (functions in some programming languages). Methods operate on an object's internal state and serve as the primary mechanism for object-to-object communication. Hiding internal state and requiring all interaction to be performed through an object's methods is known as data encapsulation — a fundamental principle of object-oriented programming.

Consider a bicycle, for example:

A picture of an object, with bibycle methods and instance variables.

A bicycle modeled as a software object.

By attributing state (current speed, current pedal cadence, and current gear) and providing methods for changing that state, the object remains in control of how the outside world is allowed to use it. For example, if the bicycle only has 6 gears, a method to change gears could reject any value that is less than 1 or greater than 6.

Bundling code into individual software objects provides a number of benefits, including:

  1. Modularity: The source code for an object can be written and maintained independently of the source code for other objects. Once created, an object can be easily passed around inside the system.

  2. Information-hiding: By interacting only with an object's methods, the details of its internal implementation remain hidden from the outside world.

  3. Code re-use: If an object already exists (perhaps written by another software developer), you can use that object in your program. This allows specialists to implement/test/debug complex, task-specific objects, which you can then trust to run in your own code.

  4. Pluggability and debugging ease: If a particular object turns out to be problematic, you can simply remove it from your application and plug in a different object as its replacement. This is analogous to fixing mechanical problems in the real world. If a bolt breaks, you replace it, not the entire machine.


In the real world, you'll often find many individual objects all of the same kind. There may be thousands of other bicycles in existence, all of the same make and model. Each bicycle was built from the same set of blueprints and therefore contains the same components. In object-oriented terms, we say that your bicycle is an instance of the class of objects known as bicycles. A class is the blueprint from which individual objects are created.
The following Bicycle class is one possible implementation of a bicycle:


class Bicycle {

int cadence = 0;
int speed = 0;
int gear = 1;

void changeCadence(int newValue) {
cadence = newValue;
}

void changeGear(int newValue) {
gear = newValue;
}

void speedUp(int increment) {
speed = speed + increment;
}

void applyBrakes(int decrement) {
speed = speed - decrement;
}

void printStates() {
System.out.println("cadence:"+cadence+" speed:"+speed+" gear:"+gear);
}
}


The syntax of the Java programming language will look new to you, but the design of this class is based on the previous discussion of bicycle objects. The fields cadence, speed, and gear represent the object's state, and the methods (changeCadence, changeGear, speedUp etc.) define its interaction with the outside world.
You may have noticed that the Bicycle class does not contain a main method. That's because it's not a complete application; it's just the blueprint for bicycles that might be used in an application. The responsibility of creating and using new Bicycle objects belongs to some other class in your application.

Here's a BicycleDemo class that creates two separate Bicycle objects and invokes their methods:


class BicycleDemo {
public static void main(String[] args) {

// Create two different Bicycle objects
Bicycle bike1 = new Bicycle();
Bicycle bike2 = new Bicycle();

// Invoke methods on those objects
bike1.changeCadence(50);
bike1.speedUp(10);
bike1.changeGear(2);
bike1.printStates();

bike2.changeCadence(50);
bike2.speedUp(10);
bike2.changeGear(2);
bike2.changeCadence(40);
bike2.speedUp(10);
bike2.changeGear(3);
bike2.printStates();
}
}

The output of this test prints the ending pedal cadence, speed, and gear for the two bicycles:
cadence:50 speed:10 gear:2
cadence:40 speed:20 gear:3

Object-Oriented Programming Concepts

Object-oriented programming (OOP) is a programming paradigm that uses "objects" – data structures consisting ofdata fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction, encapsulation, modularity, polymorphism, and inheritance. It was not commonly used in mainstream software application development until the early 1990s. Many modern programming languages now support OOP.

There are several part to know what OOP is,
2. Instance
3. Method
4. Message passing
6. Abstraction
7. Encapsulation
8. (Subtype) polymorphism
9. Decoupling

Object and Class
A Class is a user defined datatype which contains the variables, properties and methods in it. A class defines the abstract characteristics of a thing (object), including its characteristics (its attributes, fields or properties) and the thing's behaviors (the things it can do, or methods, operations or features). One might say that a class is a blueprint or factory that describes the nature of something. For example, the class Dog would consist of traits shared by all dogs, such as breed and fur color (characteristics), and the ability to bark and sit (behaviors). Classes provide modularity and structure in an object-oriented computer program. A class should typically be recognizable to a non-programmer familiar with the problem domain, meaning that the characteristics of the class should make sense in context. Also, the code for a class should be relatively self-contained (generally using encapsulation). Collectively, the properties and methods defined by a class are called members.

instance
One can have an instance of a class; the instance is the actual object created at run-time. In programmer vernacular,the Lassie object is an instance of the Dogclass. The set of values of the attributes of a particular object is called its state. The object consists of state and the behavior that's defined in the object's classes

Method
Method is a set of procedural statements for achieving the desired result. It performs different kinds of operations on different data types. In a programming language, methods (sometimes referred to as "functions") are verbs. Lassie, being a Dog, has the ability to bark. So bark() is one of Lassie's methods. She may have other methods as well, for example sit() or eat() or walk() or save(Timmy). Within the program, using a method usually affects only one particular object; all Dogs can bark, but you need only one particular dog to do the barking

Message passing
"The process by which an object sends data to another object or asks the other object to invoke a method."[13] Also known to some programming languages as interfacing. For example, the object called Breeder may tell the Lassie object to sit by passing a "sit" message which invokes Lassie's "sit" method. The syntax varies between languages, for example: [Lassie sit] in Objective-C. In Java, code-level message passing corresponds to "method calling". Some dynamic languages use double-dispatch or multi-dispatch to find and pass messages.


Inheritance

Inheritance is a process in which a class inherits all the state and behavior of another class. this type of relationship is called child-Parent or is-a relationship. "Subclasses" are more specialized versions of a class, which inherit attributes and behaviors from their parent classes, and can introduce their own.

For example, the class Dog might have sub-classes called Collie, Chihuahua, and GoldenRetriever. In this case, Lassie would be an instance of theCollie subclass. Suppose the Dog class defines a method called bark() and a property called furColor. Each of its sub-classes (Collie, Chihuahua, andGoldenRetriever) will inherit these members, meaning that the programmer only needs to write the code for them once.

Each subclass can alter its inherited traits. For example, the Collie subclass might specify that the default furColor for a collie is brown-and-white. TheChihuahua subclass might specify that the bark() method produces a high pitch by default. Subclasses can also add new members. The Chihuahuasubclass could add a method called tremble(). So an individual chihuahua instance would use a high-pitched bark() from the Chihuahua subclass, which in turn inherited the usual bark() from Dog. The chihuahua object would also have the tremble() method, but Lassie would not, because she is a Collie, not a Chihuahua. In fact, inheritance is an "a... is a" relationship between classes, while instantiation is an "is a" relationship between an object and a class: aCollie is a Dog ("a... is a"), but Lassie is a Collie ("is a"). Thus, the object named Lassie has the methods from both classes Collie and Dog.

Multiple inheritance is inheritance from more than one ancestor class, neither of these ancestors being an ancestor of the other. For example, independent classes could define Dogs and Cats, and a Chimera object could be created from these two which inherits all the (multiple) behavior of cats and dogs. This is not always supported, as it can be hard to implement.


Abstraction

Abstraction is simplifying complex reality by modeling classes appropriate to the problem, and working at the most appropriate level of inheritance for a given aspect of the problem.

For example, Lassie the Dog may be treated as a Dog much of the time, a Collie when necessary to access Collie-specific attributes or behaviors, and as an Animal (perhaps the parent class of Dog) when counting Timmy's pets.


Encapsulation

Encapsulation conceals the functional details of a class from objects that send messages to it.

For example, the Dog class has a bark() method variable,data. The code for the bark() method defines exactly how a bark happens (e.g., by inhale() and then exhale(), at a particular pitch and volume). Timmy, Lassie's friend, however, does not need to know exactly how she barks. Encapsulation is achieved by specifying which classes may use the members of an object. The result is that each object exposes to any class a certain interface — those members accessible to that class. The reason for encapsulation is to prevent clients of an interface from depending on those parts of the implementation that are likely to change in the future, thereby allowing those changes to be made more easily, that is, without changes to clients. For example, an interface can ensure that puppies can only be added to an object of the class Dog by code in that class. Members are often specified as public, protected or private, determining whether they are available to all classes, sub-classes or only the defining class. Some languages go further: Java uses the default access modifier to restrict access also to classes in the same package, C# and VB.NET reserve some members to classes in the same assembly using keywords internal (C#) or Friend (VB.NET). Eiffel and C++ allow one to specify which classes may access any member.


Polymorphism

Polymorphism allows the programmer to treat derived class members just like their parent class's members. More precisely, Polymorphism in object-oriented programming is the ability of objects belonging to different data types to respond to calls of methods of the same name, each one according to an appropriate type-specific behavior. One method, or an operator such as +, -, or *, can be abstractly applied in many different situations. If a Dog is commanded to speak(), this may elicit a bark(). However, if a Pig is commanded to speak(), this may elicit an oink(). Each subclass overrides the speak() method inherited from the parent class Animal.


Decoupling

Decoupling allows for the separation of object interactions from classes and inheritance into distinct layers of abstraction. A common use of decoupling is to polymorphically decouple the encapsulation, which is the practice of using reusable code to prevent discrete code modules from interacting with each other. However, in practice decoupling often involves trade-offs with regard to which patterns of change to favor. The science of measuring these trade-offs in respect to actual change in an objective way is still in its infancy.

inHeritance is

Inheritance is a process in which a class inherits all the state and behavior of another class. this type of relationship is called child-Parent or is-a relationship. "Subclasses" are more specialized versions of a class, which inherit attributes and behaviors from their parent classes, and can introduce their own.

For example, the class Dog might have sub-classes called Collie, Chihuahua, and GoldenRetriever. In this case, Lassie would be an instance of theCollie subclass. Suppose the Dog class defines a method called bark() and a property called furColor. Each of its sub-classes (Collie, Chihuahua, andGoldenRetriever) will inherit these members, meaning that the programmer only needs to write the code for them once.

Each subclass can alter its inherited traits. For example, the Collie subclass might specify that the default furColor for a collie is brown-and-white. TheChihuahua subclass might specify that the bark() method produces a high pitch by default. Subclasses can also add new members. The Chihuahuasubclass could add a method called tremble(). So an individual chihuahua instance would use a high-pitched bark() from the Chihuahua subclass, which in turn inherited the usual bark() from Dog. The chihuahua object would also have the tremble() method, but Lassie would not, because she is a Collie, not a Chihuahua. In fact, inheritance is an "a... is a" relationship between classes, while instantiation is an "is a" relationship between an object and a class: aCollie is a Dog ("a... is a"), but Lassie is a Collie ("is a"). Thus, the object named Lassie has the methods from both classes Collie and Dog.

Multiple inheritance is inheritance from more than one ancestor class, neither of these ancestors being an ancestor of the other. For example, independent classes could define Dogs and Cats, and a Chimera object could be created from these two which inherits all the (multiple) behavior of cats and dogs. This is not always supported, as it can be hard to implement.


Different kinds of objects often have a certain amount in common with each other. Mountain bikes, road bikes, and tandem bikes, for example, all share the characteristics of bicycles (current speed, current pedal cadence, current gear). Yet each also defines additional features that make them different: tandem bicycles have two seats and two sets of handlebars; road bikes have drop handlebars; some mountain bikes have an additional chain ring, giving them a lower gear ratio.

Object-oriented programming allows classes to inherit commonly used state and behavior from other classes. In this example,Bicycle now becomes the superclass of MountainBike, RoadBike, and TandemBike. In the Java programming language, each class is allowed to have one direct superclass, and each superclass has the potential for an unlimited number of subclasses:

A diagram of classes in a hierarchy.

A hierarchy of bicycle classes.

The syntax for creating a subclass is simple. At the beginning of your class declaration, use the extends keyword, followed by the name of the class to inherit from:

class MountainBike extends Bicycle {
// new fields and methods defining a mountain bike would go here
}
This gives MountainBike all the same fields and methods as Bicycle, yet allows its code to focus exclusively on the features that make it unique. This makes code for your subclasses easy to read. However, you must take care to properly document the state and behavior that each superclass defines, since that code will not appear in the source file of each subclass.

Tuesday, August 24, 2010

Enabling Text-to-Speech in MS Word 2007

One of my friend told me if she want to have a text-to-speech application to assist her in teaching,
then i advised her to use one of ms office feature about speech recognition, which i knew in ms office 2003, but she had been using office 2007 for her purposes.

i tried to find in ms office 2007 feature, is this text-to-speech (TTS) exist or not, like as in office 2003... And i didn't find that.

Does ms office remove all TTS feature from office 2007 or there is something to do to enable it?

After googling to find this case, apparently, it needs some trick to make TTS active :
  1. when ms word 2007 is active, press alt+F11 (hold the Alt key down then press the F11 key) to open VBA Code editor

  2. in VBA Code Editor, select on 'Normal', see on picture.



  3. then insert new module by left click > insert > module, as shown on picture.



  4. add this code into new module:
  5. Option Explicit
    Dim speech As SpVoice
    Dim i As Integer

    Sub SpeakText()
    On Error Resume Next
    If i = 0 Then
    Set speech = New SpVoice
    If Len(Selection.Text) > 1 Then 'speak selection
    speech.Speak Selection.Text, SVSFlagsAsync + SVSFPurgeBeforeSpeak
    Else 'speak whole document
    speech.Speak ActiveDocument.Range(0, ActiveDocument.Characters.Count).Text, SVSFlagsAsync + SVSFPurgeBeforeSpeak
    End If
    Else
    If i = 1 Then
    speech.Resume
    i = 0
    End If
    End If

    End Sub

    Sub Stopspeaking()
    On Error Resume Next
    speech.Speak vbNullString
    Set speech = Nothing
    i = 0

    End Sub

    Sub Pausespeaking()
    On Error Resume Next
    If i = 0 Then
    speech.Pause
    i = 1
    Else
    If i = 1 Then
    speech.Resume
    End If
    End If

    End Sub


  6. enable speech library by Select the Tools > References... menu option. Scan the list of references and click the little box next the Speech library, then click OK, see on pict



  7. save this module then return to ms word (File > Close and return to microsoft word).

  8. In order to conveniently run your macros, you will probably want to add three buttons to the quick access tool bar. You can do this by clicking the small downward arrow with the "Customize quick access toolbar" tooltip on the title bar of MS Word near the Save, Undo and Redo buttons. Select "More commands" in the dropdown menu to open the "Word options" window. Select "Customize" on left hand menu and "Choose commands from" should be set to "Macros". Add all three macros and this will create three buttons on the quick access tool bar. You can modify the button icons to more closely represent the TTS functions.

  9. Now your MS word is TTS enabled. Just click the Start, Pause, or Stop button

Sunday, August 15, 2010

Bajaj Pulsar 135LS, Honda New MegaPro or Yamaha Byson

Bajaj Pulsar 135LS

Engine:
Type 4 stroke, air cooled, 4-valve, single cylinder, SOHC, DTS-i
Displacement (cc) 134.66cc
Max. Power (Ps @ RPM) 13.5 @ 9000 rpm
Max. Torque (Nm @ RPM) 11.4 @ 7500
Starting Kick + Self start

Suspension
Front Telescopic Front Fork with antifriction bush (Stroke 130)
Rear Trailing arm with Co Axial Hydraulic cum Gas filled adjustable
Shock Absorbers and Triple rate Coil Spring

Brakes
Front Disc (Diameter 240 mm)
Rear Drum (Diameter 130 mm)

Tyre
Front & Wheel Size Tubetype Unidirectional – 2.75 x 17″ & 1.4 X 17, 5 Spoke Alloy
Rear & Wheel Size Tubetype Unidirectional – 100 / 90 x 17″ & 2.15 X 17, 5 Spoke Alloy

Fuel Tank
Total litres (reserve, usable) Capacity : 8 litres, Reserve : 2.5 litres (1.6 litres usable)

Electricals
System 12 V Full DC
Headlamp (Low/High Beam- Watts) 35/35 W with 2 pilot lamps

Dimensions
Wheelbase 1325 (mm)
Ground clearance 170 mm
Kerb Weight 122 Kg

Key Features
Auto Choke Yes
Clip-on handle bar Yes
Speedometer Digital
Tachometer Digital type with analog display
Fuel gauge Digital
Tripmeter Digital
Wheel type Alloy


Honda New MegaPro

* Panjang X lebar X tinggi : 2.050 x 757 x 1.075 mm
* Jarak Sumbu Roda : 1.313 mm
* Jarak terendah ke tanah : 152 mm
* Berat kosong : 136 kg
* Tipe rangka : Pola Berlian (diamond steel)
* Tipe suspensi depan : Teleskopik
* Tipe suspensi belakang : Tunggal (monoshock) dapat di setel keras dan lembut
* Ukuran ban depan : 80/100 – 17 M/C 46P – Tubeless
* Ukuran ban belakang : 100/80 – 17 M/C 55P – Tubeless
* Rem depan : Cakram hidrolik, dengan piston ganda
* Rem belakang : Cakram hidrolik dengan piston tunggal
* Kapasitas tangki bahan bakar : 12,0 liter
* Tipe mesin : 4 langkah, OHC, pendinginan udara
* Diameter x langkah : 57,3 x 57,8 mm
* Volume langkah : 149,2 cc
* Perbandingan Kompresi : 9,5 : 1
* Daya Maksimum : 10,1 kW / 8.500 rpm
* Torsi Maksimum : 12,8 Nm / 6.500 rpm
* Kapasitas Minyak Pelumas Mesin : 1 liter pada penggantian periodik
* Kopling Otomatis : Manual, Multiplate Wet Clutch
* Gigi Transmsi : 5 kecepatan
* Pola Pengoperan Gigi : 1-N-2-3-4-5
* Starter : Pedal & starter elektrik
* Aki : MF 12 V – 5 Ah
* Busi : NGK CPR8EA-9 / NGK CPR9EA-9
* Sistem Pengapian : DC – CDI



Yamaha Byson

Engine
Engine type Air-cooled, 4-stroke, SOHC, 2-valve
Displacement 153.0cm3
Bore & Stroke 58.0 × 57.9mm
Compression ratio 9.5:1
Maximum output 14PS / 7500 rpm
Maximum torque 14 N.m / 6000 rpm
Starting method Electric starter
Lubrication type Wet sump
Carburetor type BS26
Clutch type Constant mesh wet multiplate
Ignition type CDI
Primary/secondary reduction ratio 3.409 / 2.857
Transmission type Return type 5-speed

Chassis
Frame type Diamond
Suspension (front/rear) Telescopic / Monocross
Wheelbase 1,335mm
Brake type(front/rear) Hydraulic single disc / drum
Tire size (front/rear) 100/80-17 / 120/60-R17

Dimensions
Overall Length × Width × Height 1,975mm × 770mm × 1,045mm
Seat height 790mm
Wheelbase 1,335mm
Minimum ground clearance 160mm
Dry weight/Curb weight 126 kg / 137 kg
Fuel tank volume 12 liters
Engine oil volume 1.2 liters