Presentation is loading. Please wait.

Presentation is loading. Please wait.

Visual Basic: An Object Oriented Approach 3 – Making Objects Work.

Similar presentations


Presentation on theme: "Visual Basic: An Object Oriented Approach 3 – Making Objects Work."— Presentation transcript:

1 Visual Basic: An Object Oriented Approach 3 – Making Objects Work

2 Object Structure An Object has an internal structure that defines its state or identity has an interface through which other objects can work with it

3 Internal Structure and Operations The state of an object is the set of values of its attributes these are stored in variables, whose value can change over time they can be altered or manipulated by operations, known as program statements

4 Operators Operators work on values and variables to perform simple arithmetic (+, -, *, / …) string (text) manipulation date manipulation other forms of calculation assignment (=) comparison (=, >, =, <=, Like) Values, variables and operators can be put together (using a form of grammar) to form expressions

5 Expressions An expression is a combination of values, variables and operators has a value (found by calculating the expression) has a type of value (e.g. number, string, date…) can be a direct replacement for a value of the appropriate type x+2 “Joe” & “ Bloggs” Date + 7 (1 week from today) z * (x + 2) (=z * 3 if x is 1) x+2 “Joe” & “ Bloggs” Date + 7 (1 week from today) z * (x + 2) (=z * 3 if x is 1)

6 Conditions Conditions are expressions that evaluate to True or False Use conditions to control what happens next in a program select statements to execute repeat certain statements until a condition is True If age >= 18 Then buy beer Else buy soft drink End If If age >= 18 Then buy beer Else buy soft drink End If Do sit driving test Loop Until Result=“Pass” Do sit driving test Loop Until Result=“Pass”

7 Abstraction To create a computer program, we must create an abstraction Remove all unnecessary details Retain all info necessary to the calculations

8 Object Orientation In Object-Oriented programs, Objects are abstractions of real-world things We often refer to this a Modelling An object is a model of something we represent in a program The object Interface is how we manipulate it

9 Statements A statement is the fundamental syntactical element of a program smallest piece of code that the language will accept in its own right A statement can be used to set aside space for data storage (variables) assign a value to a variable perform a calculation and assign its result to a variable execute a previously-defined operation control other statements

10 Example statements Dim x As Integer, y As Single x = 2 x = x + 4 If x > 3 Then y = Sqr(x) Print y End If Declares variables Assigns a value to the variable Assigns the result of an expression Controls other statements Executes a pre- defined operation

11 Statements in Objects Operations in objects are sequences of statements Can change the state of the object by changing the value of one or more variables Can retrieve data from the object Could do both In general A Sub is a sequence of statements that does something to the state of an object A Function is a sequence of statements that retrieves a value based on the values of the object’s member variables A Property is a set of statements that reflect an attribute of the object, allowing it to be read or changed Sometimes, these distinctions can become blurred

12 Inter-object communication One object (the Client) makes use of another object (the Server) by sending it a message The message is a statement within one of the Client’s methods (operations). Account.Deposit 100.00 (Account)(ATM) Deposit (100.00) This statement is an operation in the ATM object


Download ppt "Visual Basic: An Object Oriented Approach 3 – Making Objects Work."

Similar presentations


Ads by Google