Giter Site home page Giter Site logo

swift-vendingmachineapp's Introduction

자판기 앱

  • 기간 : 2021.03 - 2021.03

  • 사용 언어 : Swift

  • 개발 인원: iOS(1명)

  • 관련 기술: OOP, MVC, NSCoding, Archive, MetaType, Notification Center

프로그래밍 요구사항

  • 객체지향 프로그래밍 방식으로 아래 예시 음료를 추상화하는 클래스(class)를 설계한다.

앱 주요 기능

- 자판기 음료 재고 관리 기능 
- 자판기 내 음료 구매 기능
- 앱 종료 후 재고 상태 유지 기능

상속 관계

beverage   1단계
	Milk , Soda , Coffee  2단계
		StrawberryMilk, DietCola, TopAmericano  3단계

각 상품에 대해 클래스 객체로 구분하기 위해 상품명을 클래스로 만들어 구성하였습니다

상품들은 각각의 브랜드가 있기 때문에 브랜드는 미리 지정을 하고 이름,가격,용량,제조일자 받도록 하였습니다

스크린샷 2021-02-23 오후 3 50 31


앱 시연

스크린샷 2021-11-24 오후 4 28 29 스크린샷 2021-11-24 오후 4 28 45 스크린샷 2021-11-24 오후 4 28 57
ezgif com-video-to-gif-8 ezgif com-video-to-gif-9 ezgif com-video-to-gif-10

진행 과정 중 문제점 및 해결 방안

  • 문제점: 버튼 Action을 통해 음료 객체를 생성하고 음료를 전달하여 의존성 증가
// 아메리카노 버튼 UI
override func increase(action : ((Beverage) -> Void)?) {
        action?(TopAmericano()) 
}

// 뷰컨트롤러
@IBAction func buyBeverageButtonTouched(_ sender: BeveragesButton) {
        sender.increase(action: { (beverage) in
            self.vendingMachine.addStock(beverage: beverage)
            self.numberOfStock[sender.tag].text = String(self.vendingMachine.countDrink(beverage: beverage))
   })
}
  • 해결 방안: 버튼 객체와 음료타입을 딕셔너리로 지정시키는 객체를 만들어 버튼과 음료객체의 의존성을 제거
    • 버튼은 action 시 action 한 버튼과 연결되어 있는 음료 타입이 값이 전달되도록 변경
class BeverageMapper {
    static let drinkTypeList = [StrawberryMilk.self, DietCola.self, TopAmericano.self]
    private var map : [UIButton : Beverage.Type] = [:]

    init(drinkButtons : [UIButton]) {
        self.map = Dictionary(uniqueKeysWithValues: zip(drinkButtons, BeverageMapper.drinkTypeList))
    }
    subscript(button : UIButton) -> Beverage.Type? {
        return map[button]
    }
}


// 뷰컨트롤러
@IBOutlet var PurchaseButtons: [UIButton]! // 음료 3개의 버튼 배열

override func viewDidLoad() {
        purchaseMenu = BeverageMapper(drinkButtons: PurchaseButtons)
			  ...
}

@IBAction func purchaseButtonTouched(_ sender: UIButton) {
        guard let beverageType = purchaseMenu[sender] else { return }
        vendingMachine.purchaseBeverage(beverageType: beverageType)
}

swift-vendingmachineapp's People

Contributors

hoonhachoi avatar godrm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.