OOD Icon

FOUNDATIONS OF PROGRAMMING OBJECT-ORIENTED DESIGN (PART 01-02-01)

Object-Oriented Analysis and Design

Understanding the object-oriented analysis and design processes

Whether you use software development mythology or not these are the entire point of object oriented analysis and design. What class does you need and what are they do? Lot of formal mythology has their own unique name for work through their process but although there are multiple processes to approach this, the ideas are very similar. We go through using five steps:-

  1. Gather Requirements
  2. Describe the App
  3. Identify the main object
  4. Describe the Interactions (between objects)
  5. Create class Diagram

We are going all of these more details on technics to each step later now discus basic concept.

  1. Gather Requirements:-

What is the app needs to do? What problem are you trying to solve? You focus it and you write it on a paper.

  1. Describe the App:-

You build simply narrative how people use the app. You are not trying to write a book but you are trying to describe specific technic for this including use case, use story. This may be inaccurate, may be incomplete, may be changed that’s ok we still do it.

You may or may not at this point also create a markup or prototype of the user interface. Sometimes that is essential.

  1. Identify the main objects:-

This is the actually the starting point of identifying you actual classes. So you are trying to use stories, the descriptions you just wrote to pick up the most important idea, most important concepts, the most important things in our application, not everything we pick here will become a class but, lot of them will.

  1. Describe the Interactions:-

As you then formally the interaction between those objects, this also lets you start a better understanding the responsibilities of the different objects, the behaviors I need to have when they interact what they do and what order they need to do, this is call a sequence diagram.

  1. Create a Class Diagram:-

This is a visual representation of the classes you need and here we get to really specific about object orientation principal like inheritance, polymorphism.

But no point any of these you wrote code yet, the output is on paper, on index card, on white board it could be done using electronic tools but it is really better on paper for now. The main result you expect from the process is that Class Diagram – that is the most common way you write down the classes you need to make, the methods of the classes and the interaction between the different objects in your application. In an iterative approach to developing software this is not done once, you’ll continually re-visit refine these steps over weeks and month of development.

OOD Icon

FOUNDATIONS OF PROGRAMMING OBJECT-ORIENTED DESIGN (PART 01-01-07)

Core Concepts

What is polymorphism?

Finally we have Polymorphism which means “many forms”. It is most complex term but very powerful. It lets us automatically do the correct behavior even we are working with many different forms.

Example:

+ (plus sign), what is this do? It depends on programming languages. If we add two variables with the plus sign, if the variable contains numeric value result will be summation of them, if the variable contain string value result will be concatenation of them.

We can use the same idea with our own class to make objects.

Example:

BankAccount
AccountNameBalance
Deposit()Withdrow()
SavingAccount
Has everything from BankAccount
InterestRate
ChekingAccount
Has everything from BankAccount
LastCheckNum
InvestmentAccount
Has everything from BankAccount
Withdrow()

If I define a BankAccounnt class and describe attributes like AccountName, Balance and methods like Deposit(), Withdraw() . We can then create some sub classes from it like SavingAccount, CheckingAccount, InvestmentAccount. The class BankAccount shares the basic information to subclasses or other away we can say – the subclasses inheriting the basic information from the parent class. So they have an AccountName, Balance, Deposit(), Withdraw(). The SavingAccount have new attribute InterestRate, the CheckingAccount have new attribute LastCheckNum but, a little bit more complex say the business rules says – if you withdraw from an investment account you should get penalty without 30 day notice. That withdraw behavior is originally defined in the BankAccount class and already inheriting it but I can re-write a special version just for the investment class and this is call overriding method from the superclass. So inheriting when useful but, overriding when that useful.

Polymorphism lets us freely work with objects that have been created from any of these classes. So I have now array of these different objects and I can call withdraw method on any one of them without knowing what class is extended and they will do the correct behavior for each one. When learning object orientation, learn polymorphism concept. A lot of people say I technically understand it and can use it, that’s ok. Most of your class will need it, we don’t have to go looking for polymorphism situations they occur naturally and, understanding the basic idea will enough for us to move forward.

OOD Icon

FOUNDATIONS OF PROGRAMMING OBJECT-ORIENTED DESIGN (PART 01-01-06)

Core Concepts

What is inheritance?

We can create a new class but, instead of writing from scratch we can base an existing class.

Example, in an object oriented language a better way is that we can create a new class called customer inheritance from the person class. That means our new customer class automatically has everything that the person class has, all the attributes, behavior without writing any code and we can add new attribute, behavior to customer class. The relationship between these two classes called parent-child /superclass-subclass. We can create another new class employee and inherit from person class. The great things are when we make a change in person class it will automatically filter down and affect the two sub classes. C++ allow you to inherit from more than one supper class and bring attributes, behavior from multiple supper classes but that can get confusing. It’s much more common when you doing inheritance you only inherit form one supper class enforce by Java, C#, Objective C. One of the best about the inheritance –“not just the time we save and being able to reuse code”.

OOD Icon

FOUNDATIONS OF PROGRAMMING OBJECT-ORIENTED DESIGN (PART 01-01-05)

Core Concepts

What is encapsulation?

Think a capsule, a food container this is the idea of surrounding something not just keep the contents together but also protect those contents.

In object orientation we will take attributes, behaviors bundling them together in the same unite/ class. We also want to restrict / protect access to any object based on that class. This is as to information hiding or data hiding. The principal is that an object should not access anything about itself but, will access what is absolutely necessary for the other parts of the application to work, not only for security but also reduce dependency between different parts of the application.

A common question from new OO Programmer – I am writing these classes why should I hide my own code from myself? Here is the thing – it is not about secrete it is about reducing dependency between different part of the app but, how much should I hide? – The rule is as much as possible. Different programming languages have different levels of support for these concepts. The idea of encapsulation is what you enclosed your object attributes, methods and then you hide everything about that object except what is absolutely necessary to expose. We will put in abstracting, encapsulating of our classes still be very useful when creating other classes as we see with inheritance.

 

OOD Icon

Foundations of Programming Object-Oriented Design (part 01-01-04)

Core Concepts

What is abstraction?

There are four fundamental ideas in object oriented programming, four things to keep in mind when creating class.

A Abstraction
P Polymorphism
I Inheritance
E Encapsulation

You do most of them daily conversation even you don’t use the words. If I say a table, you know what I mean by the word table. I did not say a wooden table or glass table, a large table or a small table but, you have an image of a table in your mind. I did not say that specific because you understand the idea of the table the abstraction of the table.

Abstraction means we focus on the essential relevance of something rather than one specific example. So abstraction means we can have an idea or concept that is completely separate from any specific instance. It is the heart of object oriented programming because what we doing when we make a class.

Abstraction means we don’t create Jack’s bank account class and, another separate class for Joy’s bank account. We will create essential relevant things of one bank account class. We focus on things like each of this bank account will have an account number, balance we discourage which is unimportant. It might be true every bank account is open on a specific date but if our app does not care about the date we don’t need to define the attribute in our class.

Abstraction is the foundation that supports other fundamental of object orientation such as inheritance and polymorphism.