深入淺出物件導向分析與設計

Head First Object-Oriented Analysis and Design

這一本深入淺出物件導向分析設計(中文版)是最近在看的書,真的非常深入淺出,我一個下午就看了快400頁,當然像當故事這樣看很快,有時候才會對內容注意一下:

2010-02-02_112213

因為最近在準備SCJP所以對Attribute(屬性)跟Operation(操作)就比較注意,看了這個連連看得答案就覺有問題,我倒是認為Attribute應該是連Equivalent to a member variable in a class(等同於類別裡的成員變數),Operation是連This is the UML term that usually represents a method in one of your classes.(這是UML的術語,通常代表類別裡的方法)。

各位覺得如何?

※2022/02/13

此書已絕版,無法購買,只能從圖書館借閱,有找到【深入淺出物件導向分析與設計】第一章、偉大軟體由此開始的分享,也是用C#語言實作,或許改天可以問他看看,如果朋友有深入淺出物件導向分析與設計pdf的話,可以分享一下,謝謝!

這裡轉錄一下他紀錄的心得:

情境

客戶:Rick 的亂彈吉他店

需求:建立吉他庫存管理應用程式,並提供搜尋功能,為客戶配對心目中的理想吉他。

廠商:「低階編程」軟體公司

顧客:Erin (來到 Rick 的店尋找心目中理想的吉他)

版次:v0.1

【類別圖】

【程式碼】

Guitar.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ricksGuitars_start
{
    public class Guitar
    {
        private string serialNumber, builder, model, type, backWood, topWood;
        private double price;

        public Guitar(string serialNumber, double price, string builder, string model, string type, string backWood, string topWood)
        {
            this.serialNumber = serialNumber;
            this.price = price;
            this.builder = builder;
            this.model = model;
            this.type = type;
            this.backWood = backWood;
            this.topWood = topWood;
        }

        public string getSerialNumber()
        {
            return serialNumber;
        }

        public double getPrice()
        {
            return price;
        }

        public void setPrice(double newPrice)
        {
            price = newPrice;
        }

        public string getBuilder()
        {
            return builder;
        }

        public string getModel()
        {
            return model;
        }

        public string getType()
        {
            return type;
        }

        public string getBackWood()
        {
            return backWood;
        }

        public string getTopWood()
        {
            return topWood;
        }

    }
}

Inventory.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ricksGuitars_start
{
    public class Inventory
    {
        private List<Guitar> guitars;// = new List<Guitar>();

        public Inventory()
        {
            guitars = new List<Guitar>();
        }

        public void addGuitar(string serialNumber, double price, string builder, string model, string type, string backWood, string topWood)
        {
            guitars.Add(new Guitar(serialNumber, price, builder, model, type, backWood, topWood));
        }

        public Guitar getGuitar(string serialNumber)
        {
            return guitars.First(guitar => guitar.getSerialNumber().Equals(serialNumber));
        }

        public Guitar search(Guitar searchGuitart)
        {
            //return guitars.First(guitar => guitar.Equals(searchGuitart));
            for (int i = 0; i < guitars.Count; ++i)
            {
                Guitar guitar = guitars[i];

                string builder = searchGuitart.getBuilder();
                if ((builder != null) && (!builder.Equals("")) && (!builder.Equals(guitar.getBuilder())))
                {
                    continue;
                }

                string model = searchGuitart.getModel();
                if ((model != null) && (!model.Equals("")) && (!model.Equals(guitar.getModel())))
                {
                    continue;
                }

                string type = searchGuitart.getType();
                if ((type != null) && (!type.Equals("")) && (!type.Equals(guitar.getType())))
                {
                    continue;
                }

                string backWood = searchGuitart.getBackWood();
                if ((backWood != null) && (!backWood.Equals("")) && (!backWood.Equals(guitar.getBackWood())))
                {
                    continue;
                }

                string topWood = searchGuitart.getTopWood();
                if ((topWood != null) && (!topWood.Equals("")) && (!topWood.Equals(guitar.getTopWood())))
                {
                    continue;
                }

                return guitar;

            }
            return null;

        }

    }
}

Tester.cs (測試程式表單)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System..Forms;

namespace ricksGuitars_start
{
    public partial class fmFindGuitarTester : Form
    {
        Inventory inventory = new Inventory();
        Guitar whatErinLike = new Guitar("", 0, "fender", "Stratocastor", "electric", "Alder", "Alder");

        public fmFindGuitarTester()
        {
            InitializeComponent();

            inventory.addGuitar("V95693", 1499.95, "Fender", "Stratocastor", "electric", "Alder", "Alder");
            inventory.addGuitar("V9512", 1549.95, "Fender", "Stratocastor", "electric", "Alder", "Alder");
        }

        private void fmFindGuitarTester_Load(object sender, EventArgs e)
        {
            Guitar guitar = inventory.search(whatErinLike);
            string sRet = "Sorry, we have nothing for you.";
            if (guitar != null)
            {
                sRet = "You might like this " + guitar.getBuilder() + " " + guitar.getModel() + " " +
                    guitar.getType() + " guitar : \n" + guitar.getBackWood() + " back and sides,\n" +
                    guitar.getTopWood() + " top.\nYou can have it for only $" + guitar.getPrice().ToString() + "!";
            }
            tbMsg.Text = sRet;
        }
    }
}

【測試結果】

後面還有更多改版的資訊,可以就可以看他的文章來了解,節錄至此~

※2022/03/06 後記

現在要找到中文版的深入淺出物件導向分析與設計pdf好像不好找,如果有朋友有的話,請留言給我,謝謝!
目前各位還是可以先到圖書館去借閱

若想知道一些C#的字串函式可以參閱C# Substring 定義及七種用法

Print Friendly, PDF & Email

感謝你看到這裡,很快就可以離開了,但最好的獎勵行動就是按一下幫我分享或留言,感恩喔~

點我分享到Facebook

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料