Ruby Programming Tutorial - Lesson 21 - Creating Transaction Dummy Class
ruby·@bilal-haider·
0.000 HBDRuby Programming Tutorial - Lesson 21 - Creating Transaction Dummy Class
 ## We are going to start using our Object Oriented Programming skills :) Bilal's 4 rules of programming. - Analyze the problem - Think of an object oriented solution - Make a Class of it - make object and use it :) #### Lets create a Transaction Dummy Class .. which we can later fill with real stuff to make a transaction on steemit > Create a Class that can be used to make transactions on Steemit You need to ask yourself what are the properties of a transaction, after thinking about a little bit.. and watching few transactions. you will came to know that a transaction has 5 properties - Transaction Amount - Transaction Sender - Transaction Receiver - Transaction Date - Transaction Memo There can be more properties we can also add in. like ID of transaction. But we are using only 4 properties in our transaction for now .. The beauty of Classes is, its very easy to add more properties :) ``` class Transaction def initialize(*properties) @transaction_amount = properties[0] @transaction_sender = properties[1] @transaction_receiver = properties[2] @transaction_memo = properties[3] end def send puts "Sending #{@transaction_amount} to @#{@transaction_receiver} from @#{@transaction_sender}" puts "Transaction Memo: #{@transaction_memo}" end end ``` Here is our Transaction Class, which has 2 methods. one is constructor method.. second is "send" method.. which we can fill in to make actual transactions later on ..  We have made our little style.. that we start to keep Classes in separate files and only add to programs where we need them. it makes code a lot cleaner and easy to manage . lets look at main.rb file. ``` require_relative 'transaction' _transaction = Transaction.new(0.1, "bilal-haider", "noganoo", "Awesome Transaction") _transaction.send() ``` looks like it does not have a lot of things .. but you can change this code. to take arguments from the user, which we are passing to constructor method for to create a Transaction object which we are storing inside "_transaction" local variable.. Can you take inputs from the user ? if not check out previous article.. where we used "gets" method to take input from user ...  Once we have our Class ready.. it is very easy to use it .. In upcoming articles. we will create few more Dummy Classes, e.g for Post , Vote, that we can fill in for later use. or if you can create those Classes for me.. post them in Comments Below ## Congratulations You can make Classes using the Skill now. 